#include #include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(){ int n; ll mans = 1e18; cin >> n; vector v(36); v = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; for (int k = 0; k < n; k++){ int base = 0, maxb = 0; ll ans = 0; string s; cin >> s; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < 36; j++){ if (s[i] == v[j]) maxb = max(maxb, j); } } base = ++maxb; for (ll i = s.size()-1; i >= 0; i--) { for (ll j = 0; j < 36; j++){ if (s[i] == v[j]) { ans += j*pow(base, (s.size()-i-1)); break; } } } mans = min(mans, ans); } cout << mans << endl; }