#include <bits/stdc++.h>
using namespace std;
bool isPrime(int x) {
  if (x == 1) {
    return false;
  }
  if (x == 2 || x == 3) {
    return true;
  }
  if (x % 2 == 0 || x % 3 == 0) {
    return false;
  }
  for (int i = 5; i * i <= x; i += 6) {
    if (x % i == 0 || x % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}
int gcd(int a, int b) {
  while (b > 0) {
    int temp = a;
    a = b;
    b = temp % b;
  }
  return a;
}
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void factorize(vector<pair<int, int>> &v, int num) {
  for (int i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      int cnt = 0;
      while (num % i == 0) {
        cnt++;
        num /= i;
      }
      v.push_back({i, cnt});
    }
  }
  if (num > 1) {
    v.push_back({num, 1});
  }
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
long long int power(long long int a, long long int n, long long int p) {
  long long int res = 1;
  while (n) {
    if (n % 2) {
      res = ((res % p) * (a % p)) % p;
    }
    a = ((a % p) * (a % p)) % p;
    n /= 2;
  }
  return res;
}
void sieve() {
  int arr[1000001];
  int maxN = 1000000;
  for (int i = 0; i <= maxN; i++) {
    arr[i] = -1;
  }
  for (int i = 2; i <= maxN; i++) {
    if (arr[i] == -1) {
      for (int j = 2 * i; j <= maxN; j += i) {
        if (arr[j] == -1) {
          arr[j] = i;
        }
      }
    }
  }
  int n = 28;
  while (n > 1) {
    cout << arr[n] << " x ";
    n /= arr[n];
  }
}
long long int ncr(int n, int r) {
  long long int res = 1;
  if (r > n - r) {
    r = n - r;
  }
  for (int i = 0; i < r; i++) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
int decode() {
  string s;
  cin >> s;
  int x;
  int ans = 0, y = 1;
  for (int i = 0; i < s.length(); i++) {
    ans += y;
    y++;
  }
  if (s[0] == '1') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '2') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '3') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '4') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '5') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '6') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '7') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '8') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  if (s[0] == '9') {
    x = s[0] - '0';
    ans += ((x - 1) * 10);
  }
  cout << ans << "\n";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    decode();
  }
  return 0;
}
