#include <bits/stdc++.h>
using namespace std;
void testCase(int arr[]) {
  int x;
  cin >> x;
  int y, count = 0;
  while (x) {
    y = x % 10;
    x /= 10;
    count++;
  }
  cout << arr[(y - 1) * 4 + count];
}
int main() {
  int t;
  cin >> t;
  int arr[37];
  arr[0] = 0;
  int count = 1;
  for (int i = 1; i <= 36; i++) {
    arr[i] = arr[i - 1] + count++;
    if (count > 4) count = 1;
  }
  while (t--) {
    testCase(arr);
    cout << endl;
  }
  return 0;
}
