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

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cout << "Case " << i + 1 << ':' << endl;
    int s;
    cin >> s;
    for(int j = 0; j < 10; ++j) {
      s = pow(s, 2) / 100;
      if(s >= 10000) s -= s / 10000 * 10000;
      cout << s << endl;
    }
  }
  return 0;
}