#include <iostream>
#include <cmath>
using namespace std;

int gen_rand(int r) {
  return ((r * r)%1000000)/100;
}

int main() {
  int n, r;
  cin >> n;
  for (int i=0; i<n; i++) {
    cout << "Case " << i+1 << ":" << endl;
    cin >> r;
    for (int j=0; j<10; j++) {
      r = gen_rand(r);
      cout << r << endl;
    }
  }
  return 0;
}