#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n;
  cin >> n;
  rep (iii, n) {
    cout << "Case " << iii + 1 << ":" << endl;
    int k;
    cin >> k;
    rep (i, 10) {
      k = k * k % 1000000 / 100;
      cout << k << endl;
    }
  }
  return 0;
}