#include <iostream>
#include <sstream>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <windows.h>
#include <deque>
#include <unordered_set>
#include <stack>
using namespace std;
class Operater {
public:
static unsigned int call1(unsigned int num);
};
unsigned int Operater::call1(unsigned int num){
char max_val = '0';
string str = to_string(num);
for(auto m:str){
if(m >= max_val) max_val = m;
}
int val = atoi((const char*)&max_val);
if(val < 2){
return 1;
}else{
return val;
}
}
int main() {
int test_loop = 0;
cin >> test_loop;
while (test_loop) {
test_loop--;
unsigned int S = 0;
cin >> S;
cout << (Operater::call1(S)) << endl;
}
return 0;
}