#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int tc;
  cin >> tc;
  while (tc--) {
    int x;
    cin >> x;
    int d = x % 10;
    long long cnt = 0;
    for (int i = 1; i < d; ++i) {
      cnt += 10;
    }
    int k = 1;
    while (x) {
      x /= 10;
      cnt += k;
      k++;
    }
    cout << cnt << "\n";
  }
  return 0;
}
