Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		seed, _ := strconv.Atoi(scanner.Text())
		fmt.Printf("Case %d:\n", i+1)
		for j := 0; j < 10; j++ {
			tmp := fmt.Sprintf("%08d", seed*seed)
			seed, _ = strconv.Atoi(tmp[2:6])
			fmt.Println(seed)
		}
	}
}

C++: #include "stdio.h"

int main(){
	int i,j,x;
	int n,N;
	scanf("%d\n",&N);
	char str[9];
	for(x=1;x<=N;x++){
		scanf("%d\n",&n);
		printf("Case %d:\n",x);
		for(i=0;i<10;i++){
			sprintf(str,"%08d",n*n);
			str[6] = 0;
			n = atoi(str+2);
			printf("%d\n",n);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <queue>

using namespace std;

int main()
{
  int n;
  int s;
  int x = 1;
  queue<int> qu;

  cin >> n;

  while (n--){
    cout << "Case" << x++ << ":" << endl;
    cin >> s;
    for (int i = 0; i < 10; i++){
      s = s * s;
      int t = 10000000;
      for (int cnt = 0; cnt < 8; cnt++){
        qu.push(s / t);
        s %= t;
        t /= 10;
      }
      s = 0;
      t = 1000;
      for (int cnt = 0; cnt < 8; cnt++){
        if (cnt >= 2 && cnt <= 5){
          s += qu.front() * t;
          t /= 10;
        }
        qu.pop();
      }
      cout << s << endl;
    }
  }

  return (0);
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;



int main(){

	int d,s;

	scanf("%d",&d);

	for(int i=0; i < d; i++){
		scanf("%d",&s);

		printf("Case %d:\n",i+1);
		for(int k=0; k < 10; k++){
			s = s*s;
			s /= 100;
			s %= 10000;
			printf("%d\n",s);
		}

	}

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.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=s*s;
            s/=100;
            s=s%10000;
            cout<<s<<endl;
        }

    }

}

C++: #include<iostream>
using namespace std;

int middleSquareMethod( int a )
{
    a *= a;
    a /= 100;

    int sum = 0, d = 1;
    for( int i = 0; i < 4; i++ )
    {
        sum += ( a % 10 ) * d;
        a /= 10;
        d *= 10;
    }

    return sum;
}

int main()
{
    int n, d;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> d;
        cout << "Case " << i + 1 << ":" << endl;

        int a = 10, b;
        while(a--)
        {
            b = middleSquareMethod(d);
            cout << b << endl;
            d = b;
        }
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
  int n,i,j,k;
  cin >> n;
  for(i=1;i<=n;i++){
    cin >> j;
    cout << "Case " << i << ":" << endl;
    for(k=0; k<10; k++){
      j *= j;
      j = (j % 1000000) / 100;
      cout << j << endl;
    }
  }
  return 0;
}

C++: //Name: Middle-Square Method
//Level: 1
//Category: やるだけ
//Note: 

/**
 * 8桁の数の中央4桁は、100で割ってから10000で剰余を取れば求められる。
 */
#include <iostream>
#include <algorithm>

using namespace std;

void solve(int CASE) {
    int N;
    cin >> N;
    cout << "Case " << CASE << ":" << endl;
    for(int i = 0; i < 10; ++i) {
        N *= N;
        N = N / 100 % 10000;
        cout << N << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

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

C++: #include <iostream>
#include <cstdlib>

using namespace std;

int main(void){
	int n,s;
	scanf("%d",&n);
	for(int a=1;a<=n;a++){
		scanf("%d",&s);
		printf("Case %d:\n",a);
		for(int i=0;i<10;i++){
			char ss[8],sss[4];
			int rank=0;
			s=s*s;
			if(s>=100)rank=1;
			if(s>=1000)rank=2;
			if(s>=10000)rank=3;
			if(s>=100000)rank=4;
			if(s>=1000000)rank=5;
			if(s>=10000000)rank=6;
			itoa(s,ss,10);
			int sk=0;
			for(int j=rank-4;j<rank;j++){
				if(j>=0){
					sss[sk]=ss[j];
					sk++;
				}
			}
			s=atoi(sss);
			printf("%d\n",s);
		}
	}
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n;++i){
		long s;
		scanf(" %ld", &s);
		
		printf("Case %d:\n", i+1);
		
		for(int j=0; j<10; ++j){
			s=s*s;
			
			int a[8];
			for(int k=0; k<8; ++k) a[k]=s%(long)pow(10,8-k) / (long)pow(10, 7-k);
			
			s=0;
			for(int k=2; k<6; ++k) s+=a[k]*pow(10,5-k);
			
			printf("%ld\n", s);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    for(int c=0;c<n;c++){
        string in; cin>>in;
        cout<<"Case "<<c<<" "<<endl;
        rep(i,10){
                    int num=pow(stoi(in),2);
                    in=to_string(num);

                string t;
                int cnt=in.size();
                while(cnt++ <8)t.push_back('0');
                t+=in;
                string ans; for(int i=2;i<=6;i++){
                    ans.push_back(t[i]);
                }
                cout<<stoi(ans)<<endl;
            in=ans;
        }
    }
    cout<<endl;
}

C++: #include <iostream>
using namespace std;
int main(){
	int d,cnt=1;
	long long s;
	cin>>d;
	for(int i=1;i<=d;i++){
		cin>>s;
		for(int j=0;j<10;j++){
			s=(s*s/100)%10000;
			cout<<s<<endl;
		}
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cout << "Case " << i+1 << ":" << endl;
		for (int j = 0; j < 10; j++) {
			string s;
			x *= x;
			string t = to_string(x);
			for (int k = 0; k < 8 - t.length(); k++) {
				s += '0';
			}
			s += t;
			x = stoi(s.substr(2, 4));
			cout << x << endl;

		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>


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

#define PII pair<int,int>
#define PP pair< int,PII >

#define ci(x) (x-'0')

using namespace std;

int main(){
	
	int n;
	char str[10];
	scanf("%d", &n);
	
	rep(i,n){
		printf("Case %d:\n",i+1);
		int s;
		scanf("%d", &s);
		rep(j,10){
			s = s*s;
			sprintf(str,"%08d", s);
			s = ci(str[2])*1000+ci(str[3])*100+ci(str[4])*10+ci(str[5])*1;
			printf("%d\n",s);
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
void solve(int i) {
	int k; cin >> k;
	cout << "Case " << i << ":\n";
	for (int i = 0; i < 10; i++) {
		k = (k*k / 100) % 10000;
		cout << k << endl;
	}
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		solve(i + 1);
	}
}