#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll T, n;
ll m;
ll a[N];
ll sum;
void solve ()
{
char b[N] = {0};
cin >> b;
ll x = strlen (b);
ll num = 9 * (x - 1) + b[0] - '0';
cout << num << endl;
}
int main()
{
cin >> T;
while (T--) {
solve();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll T, n;
ll m;
ll a[N];
ll sum;
ll f;
string solve ()
{
cin >> n;
char b[N];
cin >> b;
if (n <= 3)
return "No\n";
for (int i = 0; i < n - 1; i++) {
for (int j = i + 2; j < n - 1; j++) {
if (b[i] == b[j] && b[i + 1] == b[j + 1])
return "YES\n";
}
}
return "NO\n";
}
int main()
{
cin >> T;
while (T--) {
cout << solve();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll T, n;
ll x, y;
ll a[N];
string s[2];
ll sum;
ll f, ok;
void solve () {
cin >> n;
cin >> s[0] >> s[1];
for (int i = 0; i < 2; i++) {
f = 1;
x = i;
for (int j = 0; j < n; j++) {
if (s[x][j] != 'B')
f = 0;
if (s[!x][j] == 'B')
x ^= 1;
}
if (f) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main() {
cin >> T;
while (T--) {
solve();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll T, n;
ll x, y;
ll pri[N];
string s[2];
ll sum, res;
ll f, ok;
void solve () {
cin >> x >> y;
ll d = y - x;
if (d == 1) {
cout <<"-1\n";
return;
}
res = llinf;
while (d > 1) {
int p = pri[d];
d /= p;
res = min (res, (p - x % p) % p);
}
cout << res << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 2; i <= N; i++) {
if (pri[i] == 0) {
for (int j = i; j <= N; j += i) {
pri[j] = i;
}
}
}
cin >> T;
while (T--) {
solve();
}
return 0;
}