#include <bits/stdc++.h>
using namespace std;
void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long double PI = 4 * atan((long double)1);
const int INF = 1e9 + 7;
const long long _INF = 1e18;
int main() {
  setIO();
  int t;
  cin >> t;
  while (t--) {
    int x, k = 0;
    cin >> x;
    int y = x;
    while (y) {
      y /= 10;
      k++;
    }
    cout << 10 * (x % 10 - 1) + k * (k + 1) / 2 << endl;
  }
}
