Algorithm


A. Digit Minimization
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is an integer n without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.

On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.

You have to find the smallest integer Alice can get in the end, if she plays optimally.

Input

The input consists of multiple test cases. The first line contains a single integer t (1t1041≤�≤104) — the number of test cases. Description of the test cases follows.

The first and the only line of each test case contains the integer n (10n10910≤�≤109) — the integer for the game. n does not have zeros in its decimal representation.

Output

For each test case output a single integer — the smallest integer Alice can get in the end of the game.

Example
input
Copy
3
12
132
487456398
output
Copy
2
1
3
Note

In the first test case Alice has to swap 11 and 22. After that Bob removes the last digit, 11, so the answer is 22.

In the second test case Alice can swap 33 and 11312312. After that Bob deletes the last digit: 3131. Then Alice swaps 33 and 111313 and Bob deletes 33, so the answer is 11.

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  while(t--){
    int n, k;
    cin>>n;
    int count = 0;
    int min = 10;
    k = n;
    while(k > 0){
      count++;
      if(k % 10 < min){
        min = k % 10;
      }
      k /= 10;
    }
    if(count == 2){
      cout<<(n%10)<<endl;
    }
    else{
      cout<<min<<endl;
    }
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
12
132
487456398

Output

x
+
cmd
2
1
3
Advertisements

Demonstration


Codeforcess Solution 1684-A A. Digit Minimization ,C++, Java, Js and Python ,1684-A,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+