#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
using namespace std;
const double PI = acos(-1.0);
const int MAXN = 1e6 + 55;
int vis[30];
string s;
int main() {
  int q;
  scanf("%d", &q);
  for (int test = 1; test <= q; test++) {
    int n;
    scanf("%d", &n);
    int mo = n % 10;
    int ans = (mo - 1) * 10;
    int cnt = 0;
    while (n) {
      cnt++;
      n /= 10;
    }
    ans += (cnt + 1) * cnt / 2;
    printf("%d\n", ans);
  }
}
