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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n;
  cin>>n;
  rep(i,n){
    cout<<"Case " << i + 1 << ":" << endl;
    int num;
    cin>>num;
    rep(j,10){
      num = int(pow(num,2) / 100 ) % 10000;
      cout<<num<<endl;;
    }
  }

}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n,x;
    double output;
    while(cin >> n){
        rep(i,n){
            cout << "Case " << i + 1 << ":" << endl;
            cin >> x;
            rep(j,10){
                x *= x;
                while(x >= 1000000)
                    x -= 1000000;
                output = static_cast<double>(x) / 100;
                cout << static_cast<int>(output) << endl;
                x = static_cast<int>(output);
            }
        }
    }
}

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

C++: #include<iostream> 
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;

int cont = 10;

void Smethod(int a)
{
	if(cont == 0) return;
	int y[8];
	for(int i = 0; i < 8; i++)
	{
		y[i] = a % 10;
		a = floor(a / 10);
	}
	cout << y[5] << y[4] << y[3] << y[2] << endl;
	int b = y[5]*1000 + y[4]*100 + y[3]*10 + y[2];
	cont--;
	//printf(":%d:%d:",b,b*b);
	Smethod(b*b);
}

int main(){
	int n,a;
	cin >> n;

	for(int i = 0; i < n; i++)
	{
		cin >> a;
		Smethod(a*a);
		cont = 10;
	}
}

C++: #include<iostream> 
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;

int cont = 0;

void Smethod(int a)
{
	if(cont == 10) return;
	int y[8];
	for(int i = 0; i < 8; i++)
	{
		y[i] = a % 10;
		a = floor(a / 10);
	}
	int b = y[5]*1000 + y[4]*100 + y[3]*10 + y[2];
	cout << b << endl;
	cont++;
	Smethod(b*b);
}

int main(){
	int n,a;
	cin >> n;

	for(int i = 1; i <= n; i++)
	{
		cin >> a;
		printf("Case %d:\n",i);
		Smethod(a*a);
		cont = 0;
	}
}

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

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

const int INF = 10000000;
using namespace std;
typedef long long  ll;
const int MAX = 10000;

/** Problem0137 : Middle-Square Method **/
int main()
{
	int n, s, ts;
	string str, sq;
	cin >> n;
	rep(k, n) {
		cin >> s;
		
		cout << "Case " << k+1 << ":" << endl;
		rep(j, 10) {
			ts = s*s;
			str = "";
			while (ts!=0) {
				str += ts%10+'0';
				ts/=10;
			}
			reverse(str.begin(), str.end());
			if (str.length()<8) {
				string tt;
				rep(i, 8-str.length()) tt+='0';
				str = tt+str;
			}
			string sub = str.substr(2, 4);
			s=0;
			rep(i, 4) {
				s*=10; s+=sub[i]-'0';
			}
			cout << s << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n,s;

int func(int x){
	x*=x;
	x/=100;
	x%=10000;
	return x;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		cout<<"Case "<<i+1<<':'<<endl;
		for(int i=0;i<10;i++){
			s=func(s);
			cout<<s<<endl;
		}
	}
}

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

int main(){
	long long int n;
	int w;
	cin>>w;
	for(int j=1;j<=w;j++){
		cin>>n;
		cout<<"case"<<j<<":"<<endl;
		for(int i=0;i<10;i++){
			n=n*n;
			n=((n%1000000)/100);
			cout<<n<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int i, j, n, s, t, u;

  cin >> n;

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

    for(j=0; j<10; ++j){
      s *= s;
      s /= 100;
      t = s/10000;
      s = s - t*10000;
      cout << s << endl;
    }
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
	solve();
	return(0);
}

C++: #include <stdio.h>
int rand(int s);
int main(){
	 int i,s,j,n;
	 int a[8];
	 scanf("%d",&n);
	 j = n;
	 while(n--){
		 scanf("%d",&s);
		 printf("Case %d:\n",j-n);
		 for(i=0;i<10;i++){
			 s = rand(s);
			 printf("%d\n",s);
		 }
	 }

	 return 0;
}

int rand(int s){
	int i,r=0;
	s *= s;s /= 100;
	for(i=1;i<1001;i*=10){
		r += (s%10)*i;
		s /= 10;
	}
	return r;
}
			
 /* for(i=0;i<8;i++) a[i] = 0;
		 for(i=0;i<8;i++){ 
			 a[i] = s%10;
			 s/=10;
		 }
		 for(i=2;i<6;i++){
			 s += a[i]*j;
			 j*=10;
		 }*/

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
int getDigit( long long n )
{
	int cnt = 0;
	while ( n >= 10 )
	{
		n /= 10;
		cnt++;
	}
	return cnt+1;
}
int main( void )
{
	int n;
	cin >> n;

	for ( int lpc = 0; lpc < n; lpc++ )
	{
		long long s;
		cin >> s;

		cout << "Case " << lpc+1 << ":" << endl;
		for ( int i = 0; i < 10; i++ )
		{
			int d = getDigit( s );
			s *= s;
			ostringstream os;
			os << setfill('0') << setw(8) << s << endl;
			string s_str = os.str();
			string s_next;
			s_next = s_str.substr( 2, 4 );
			istringstream is( s_next );
			is >> s;
			cout << s << endl;
		}

	}

	return 0;
}

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

void random(int s) {
  for(int i=0;i<10;i++) {
    stringstream ss;string str;
    s *= s;
    ss << s;
    ss >> str;
    int aftsize = str.size();
    if(aftsize <= 2) {
      s = 0;
    }
    else if(aftsize <= 6) {
      s = atoi(str.substr(0,aftsize-2).c_str());
    }
    else if(aftsize > 6) {
      s = atoi(str.substr(aftsize-6,4).c_str());
    }
    cout << s << endl;
  }
}

int main() {
  int n,s;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> s;
    cout << "Case " << i+1 << ":" << endl;
    random(s);
  }
}