#include <bits/stdc++.h>
using namespace std;
long long a[1000000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, i, j, c, k, m, x, y, f, ans;
  cin >> t;
  while (t--) {
    cin >> n;
    x = n % 10;
    x--;
    c = 0;
    ans = x * 10;
    while (n) {
      n /= 10;
      c++;
    }
    ans += c * (c + 1) / 2;
    cout << ans << "\n";
  }
  return 0;
}
