#include<bits/stdc++.h>
using namespace std;

void solve(){
  string str;
  cin >> str;
  for(int i = 0; i < str.length() - 1; i++){
    for(int j = 0; j < str.length() - 1; j++){
      int a;
      a = str[j] - '0' + str[j + 1] - '0';
      if(a >= 10){
        a = a % 10 + a / 10;
      }
        str[j] = '0' + a;
    }
  }
  cout << str[0] << endl;
}

int main(){
  int t;
  cin >> t;
  for(int i = 0; i < t; i++){
    solve();
  }
  return 0;
}