//Jatin Kumar
//jatiny17

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

#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define print4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";
#define s(a) sort(a.begin(),a.end());
#define lli long long int
#define ulli unsigned long long int
#define dd long double
#define pi pair<lli,lli>
#define pp pair<lli,pi>
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//***************************************************//
class solution{

	public:
		solution()
		{
			;
		}

		void solve()
		{
			lli t;
			cin>>t;

			// bool prime[10001];
			lli f[10001];

			// memset(prime,true,sizeof(prime));

			// prime[0]=false;
			// prime[1]=false;

			for(lli i=1;i<=10000;i++)
				f[i]=i;

			for(lli i=4;i<=10000;i+=2)
				f[i]=2;

			for(lli i=3;i*i<=10000;i++)
			{
				if(f[i]==i)
				{
					for(lli j=i*i;j<=10000;j+=i)
					{
						if(f[j]==j)
							f[j]=i;
					}
				}
			}

			while(t--)
			{
				lli n;
				cin>>n;

				lli a[n+1];

				for(lli i=1;i<=n;i++)
					cin>>a[i];

				lli ans[n+1];

				memset(ans,0,sizeof(ans));

				map<lli,vector<lli> >mp;
				map<lli ,vector<lli> >mp1;

				for(lli i=1;i<=n;i++)
				{
					lli temp=a[i];

					while(temp!=1)
					{
						mp[f[temp]].pb(i);
						mp1[i].pb(f[temp]);
						temp=temp/f[temp];
					}
				}
				map<lli, vector<lli> >::iterator it;

				// for(it=mp1.begin();it!=mp1.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				// for(it=mp.begin();it!=mp.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				lli ct=1;
				bool f=false;

				for(lli i=1;i<=min(n,(lli)11);i++)
					ans[i]=i;

				for(lli i=12;i<=n;i++)
				{

					{
						bool c=false;

						for(lli j=0;j<mp1[i].size();j++)
						{
							if(mp[mp1[i][j]].size()>0)
							{
								if(mp[mp1[i][j]][0]<i)
								{
									ans[i]=ans[mp[mp1[i][j]][0]];
									c=true;
									break;
								}
							}
						}

						if(!c)
						{
							ans[i]=ct;
							ct++;
						}
					}

					if(ct==12)
					{
						ct=1;
					}
				}

				set<lli> st;

				for(lli i=1;i<=n;i++)
					st.insert(ans[i]);

				cout<<st.size()<<"\n";
				for(lli i=1;i<=n;i++)
					cout<<ans[i]<<" ";

				cout<<"\n";

			}
		}
};

int main()
{
    fast;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solution s;
    s.solve();
}


//Jatin Kumar
//jatiny17

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

#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define print4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";
#define s(a) sort(a.begin(),a.end());
#define lli long long int
#define ulli unsigned long long int
#define dd long double
#define pi pair<lli,lli>
#define pp pair<lli,pi>
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//***************************************************//
class solution{

	public:
		solution()
		{
			;
		}

		void solve()
		{
			lli t;
			cin>>t;

			// bool prime[10001];
			lli f[1001];

			// memset(prime,true,sizeof(prime));

			// prime[0]=false;
			// prime[1]=false;

			for(lli i=1;i<=1000;i++)
				f[i]=i;

			for(lli i=4;i<=1000;i+=2)
				f[i]=2;

			for(lli i=3;i*i<=1000;i++)
			{
				if(f[i]==i)
				{
					for(lli j=i*i;j<=1000;j+=i)
					{
						if(f[j]==j)
							f[j]=i;
					}
				}
			}

			while(t--)
			{
				lli n;
				cin>>n;

				lli a[n+1];

				for(lli i=1;i<=n;i++)
					cin>>a[i];

				lli ans[n+1];

				memset(ans,0,sizeof(ans));

				map<lli,vector<lli> >mp;
				map<lli ,vector<lli> >pf;

				for(lli i=1;i<=n;i++)
				{
					lli temp=a[i];

					while(temp!=1)
					{
						mp[f[temp]].pb(i);
						pf[i].pb(f[temp]);
						temp=temp/f[temp];
					}
				}

				map<lli, vector<lli> >::iterator it;

				// for(it=pf.begin();it!=pf.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				// cout<<"\n";

				// for(it=mp.begin();it!=mp.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				for(lli i=1;i<=min(n,(lli)11);i++)
					ans[i]=i;

				lli ct=1;

				ans[1]=1;

				for(lli i=2;i<=n;i++)
				{
					bool c=false;

					for(lli j=i-1;j>=1;j--)
					{
						if(__gcd(a[i],a[j])>1)
						{
							ans[i]=ans[j];
							c=true;
							ct=max(ct,ans[i]);
							break;
						}
					}

					if(!c)
					{
						// cout<<i<<" ";
						ans[i]=++ct;
					}

					if(ct==12)
						ct=1;
				}

				// cout<<"\n";

				set<lli> st;

				for(lli i=1;i<=n;i++)
					st.insert(ans[i]);

				cout<<st.size()<<"\n";

				for(lli i=1;i<=n;i++)
					cout<<ans[i]<<" ";
				cout<<"\n";
			}

		}
};

int main()
{
    fast;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solution s;
    s.solve();
}


//Jatin Kumar
//jatiny17

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

#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define print4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";
#define s(a) sort(a.begin(),a.end());
#define lli long long int
#define ulli unsigned long long int
#define dd long double
#define pi pair<lli,lli>
#define pp pair<lli,pi>
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//***************************************************//
class solution{

	public:
		solution()
		{
			;
		}

		void solve()
		{
			lli t;
			cin>>t;

			lli f[1001];

			for(lli i=1;i<=1000;i++)
				f[i]=i;

			// for(lli i=4;i<=1000;i+=2)
			// 	f[i]=2;

			for(lli i=2;i*i<=1000;i++)
			{
				if(f[i]==i)
				{
					for(lli j=2*i;j<=1000;j+=i)
					{
						f[j]=i;
					}
				}
			}

			while(t--)
			{
				lli n;
				cin>>n;

				lli a[n+1];

				lli ans[n+1];
				memset(ans,0,sizeof(ans));

				for(lli i=1;i<=n;i++)
					cin>>a[i];

				map<lli ,set<lli> > pf;

				map<lli, vector<lli> >mp;

				for(lli i=1;i<=n;i++)
				{
					lli temp=a[i];

					while(temp!=1)
					{
						pf[i].insert(f[temp]);
						mp[f[temp]].pb(i);

						temp=temp/f[temp];
					}
				}

				set<lli>::iterator it_s;

				// for(lli i=1;i<=n;i++)
				// {
				// 	cout<<i<<"->";

				// 	for(it_s=pf[i].begin();it_s!=pf[i].end();it_s++)
				// 		cout<<*it_s<<" ";
				// 	cout<<"\n";
				// }

				// cout<<"\n";

				bool visited[n+1];
				memset(visited,false,sizeof(visited));

				map<lli,vector<lli> >::iterator it;

				lli ct=1;

				for(it=mp.begin();it!=mp.end();it++)
				{
					// cout<<it->ff<<"->";
					bool c=false;

					for(lli j=0;j<it->ss.size();j++)
					{
						// cout<<it->ss[j]<<" ";

						if(visited[it->ss[j]]==false)
						{
							visited[it->ss[j]]=true;
							ans[it->ss[j]]=ct;
							c=true;
						}
					}

					// cout<<"\n"<<ct<<"\n";

					// for(lli i=1;i<=n;i++)
					// cout<<ans[i]<<" ";

					// cout<<"\n";
					if(c)
					ct++;
				}
				set<lli> st;

				for(lli i=1;i<=n;i++)
					st.insert(ans[i]);

				cout<<st.size()<<"\n";

				for(lli i=1;i<=n;i++)
					cout<<ans[i]<<" ";

				cout<<"\n";
			}

		}
};

int main()
{
    fast;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solution s;
    s.solve();
}


//Jatin Kumar
//jatiny17

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

#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define print4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";
#define s(a) sort(a.begin(),a.end());
#define lli long long int
#define ulli unsigned long long int
#define dd long double
#define pi pair<lli,lli>
#define pp pair<lli,pi>
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//***************************************************//
class solution{

	public:
		solution()
		{
			;
		}

		void solve()
		{
			lli t;
			cin>>t;

			// bool prime[10001];
			lli f[1001];

			// memset(prime,true,sizeof(prime));

			// prime[0]=false;
			// prime[1]=false;

			for(lli i=1;i<=1000;i++)
				f[i]=i;

			for(lli i=4;i<=1000;i+=2)
				f[i]=2;

			for(lli i=3;i*i<=1000;i++)
			{
				if(f[i]==i)
				{
					for(lli j=i*i;j<=1000;j+=i)
					{
						if(f[j]==j)
							f[j]=i;
					}
				}
			}

			while(t--)
			{
				lli n;
				cin>>n;

				lli a[n+1];

				for(lli i=1;i<=n;i++)
					cin>>a[i];

				lli ans[n+1];

				memset(ans,0,sizeof(ans));

				map<lli,vector<lli> >mp;
				map<lli ,vector<lli> >pf;

				for(lli i=1;i<=n;i++)
				{
					lli temp=a[i];

					while(temp!=1)
					{
						mp[f[temp]].pb(i);
						pf[i].pb(f[temp]);
						temp=temp/f[temp];
					}
				}

				map<lli, vector<lli> >::iterator it;

				// for(it=pf.begin();it!=pf.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				// cout<<"\n";

				// for(it=mp.begin();it!=mp.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				// for(lli i=1;i<=min(n,(lli)11);i++)
				// 	ans[i]=i;

				lli ct=1;

				for(lli i=1;i<=n;i++)
				{
					bool c=false;

					for(lli j=0;j<pf[i].size();j++)
					{
						if(mp[pf[i][j]].size()>0)
						{
							for(lli k=0;k<mp[pf[i][j]].size();k++)
							{
								if(mp[pf[i][j]][k]<i)
								{
									ans[i]=ans[mp[pf[i][j]][k]];
									ct=max(ct,ans[i]);
									c=true;
									break;
								}
							}
						}
					}

					if(!c)
					{
						ans[i]=++ct;
					}

					if(ct==12)
						ct=1;
				}

				set<lli> st;

				for(lli i=1;i<=n;i++)
					st.insert(ans[i]);

				cout<<st.size()<<"\n";

				for(lli i=1;i<=n;i++)
					cout<<ans[i]<<" ";
				cout<<"\n";
			}

		}
};

int main()
{
    fast;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solution s;
    s.solve();
}


#include<bits/stdc++.h>
using namespace std;
int main(){long long int t,a,b,n;
cin>>t;
while(t--){cin>>a>>b>>n;
long long int a[n+1];
a[0]=0;
a[1]=1;
for(long long int i=2;i<=n;i++){a[i]=a[i-1]^a[i-2];}
cout<<a[n]<<endl;
}
return 0;}


#include<bits/stdc++.h>
using namespace std;
int main(){long int a,b,n,k,j;
cin>>a>>b>>n;
k=n%3;
j=a^b;
if(k==0){cout<<a<<endl;}
if(k==1){cout<<b<<endl;}
if(k==2){cout<<j<<endl;}
return 0;}


#include<bits/stdc++.h>
using namespace std;
int main(){long int a,b,n,k;
cin>>a>>b>>n;
k=n%3;
if(k==0){cout<<a<<endl;}
if(k==1){cout<<b<<endl;}
if(k==2){cout<<a^b<<endl;}
return 0;}


#include<iostream>
using namespace std;
int main(){int a,b,n,k;
cin>>a>>b>>n;
k=n%3;
if(k==0){cout<<a<<endl;}
if(k==1){cout<<b<<endl;}
if(k==2){cout<<a^b<<endl;}
return 0;}


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

int main()
{
    int n;
    cin>>n;
    int i;
    for(i=0;i<n;i++)
    {
        int a,b,t;
        cin>>a>>b>>t;
        if(t%2==0 && t!=0)
        {
            cout<<a^b<<endl;

        }
        else if(t==0)
        {
            cout<<a<<endl;
        }
        else if(t%2!=0 && t!=0)
        {
            cout<<a<<endl;
        }

    }
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int i,ans[n];
    for(i=0;i<n;i++)
    {
        int a,b,t,temp,c;
        cin>>a>>b>>t;
        c=a^b;
        temp=t%3;
        if(t==0)
        {
            ans[i]=a;
        }
        else if(t==1)
        {
            ans[i]=b;
        }
        else if(t==2)
        {
            ans[i]=c;
        }

    }

    for(i=0;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int i,ans[n];
    for(i=0;i<n;i++)
    {
        int a,b,t;
        cin>>a>>b>>t;
        if(t%2==0 && t!=0)
        {
            int c=a^b;
            ans[i]=c;

        }
        else if(t==0)
        {
            ans[i]=a;
        }
        else if(t%2!=0 && t!=0)
        {
            ans[i]=a;
        }

    }

    for(i=0;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int i,ans[n];
    for(i=0;i<n;i++)
    {
        int a,b,t,temp;
        cin>>a>>b>>t;
        c=a^b;
        temp=t%3;
        if(t==0)
        {
            ans[i]=a;
        }
        else if(t==1)
        {
            ans[i]=b;
        }
        else if(t==2)
        {
            ans[i]=c;
        }

    }

    for(i=0;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int i,ans[n];
    for(i=0;i<n;i++)
    {
        int a,b,t;
        cin>>a>>b>>t;
        if(t%2==0 && t!=0)
        {
            int c=a^b;
            ans[i]=c;

        }
        else if(t==0)
        {
            ans[i]=a;
        }
        else if(t%2!=0 && t!=0)
        {
            ans[i]=a;
        }

    }

    for(i=0;i<n;i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}


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

int main()
{
    long long int n;
    cin>>n;
    long long int i,ans[n];
    for(i=0;i<n;i++)
    {
        int a,b,c;
        long long int t,temp;
        cin>>a>>b>>t;

        c=a^b;
        temp=t%3;
        if(temp==0)
        {
            ans[i]=a;
        }
        else if(temp==1)
        {
            ans[i]=b;
        }
        else if(temp==2)
        {
            ans[i]=c;
        }

    }

    for(i=0;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main()
{
    long long int n;
    cin>>n;
    long long int i,ans[n];
    for(i=0;i<n;i++)
    {
        long long int a,b,t,temp,c;
        cin>>a>>b>>t;
        c=a^b;
        temp=t%3;
        if(t==0)
        {
            ans[i]=a;
        }
        else if(t==1)
        {
            ans[i]=b;
        }
        else if(t==2)
        {
            ans[i]=c;
        }

    }

    for(i=0;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


#include <stdio.h>

int main(void) {
  int t,i;
  scanf("%d",&t);
  int ans[t];
  for(i=0;i<t;i++)
  {
    int a,b,n;
    scanf("%d%d%d",&a,&b,&n);
    if(n%3==1)
    ans[i]=b;
    else if(n%3==0)
    ans[i]=a;
    else ans[i]=a^b;
  }
  for(i=0;i<t;i++)
  printf("%d\n",ans[i]);
}


#include <stdio.h>

int main(void) {
  int t,i;
  scanf("%d",&t);
  for(i=0;i<t;i++)
  {
    int a,b,n;
    scanf("%d%d%d",&a,&b,&n);
    if(n%3==1)
    printf("%d",a);
    else if(n%3==0)
    printf("%d",b);
    else printf("%d",a^b);
  }
}


#include <stdio.h>

int main(void) {
  long long int a,b,n,t,i,j;
  scanf("%lld",&t);
  for(i=0;i<t;i++)
  {
    scanf("%lld%lld%lld",&a,&b,&n);
    int ans[n+1];
    ans[0]=a;
    ans[1]=b;
    for(j=2;j<=n;j++)
    {
      ans[j]=ans[j-1]^ans[j-2];
    }
    printf("\n");
    printf("%d",ans[n]);
    return 0;
  }
}


#include <stdio.h>

int main(void) {
  int t;
  scanf("%d",&t);
  long int a,b,n[t],fin[t],i,j;
  for(i=0;i<t;i++)
  {
    scanf("%ld%ld%ld",&a,&b,&n[i]);
    int ans[n[i]+1];
    ans[0]=a;
    ans[1]=b;
    for(j=2;j<=n[i];j++)
    {
      ans[j]=ans[j-1]^ans[j-2];
    }
    fin[i]=ans[n[i]];
  }
  for(i=0;i<t;i++)
  printf("%ld\n",fin[i]);
}


#include <stdio.h>

int main(void) {
  int t;
  scanf("%d",&t);
  long long int a[t],b[t],n[t],fin[t],i,j;
  for(i=0;i<t;i++)
  {
    scanf("%lld%lld%lld",&a[i],&b[i],&n[i]);
    int ans[n[i]+1];
    ans[0]=a[i];
    ans[1]=b[i];
    for(j=2;j<=n[i];j++)
    {
      ans[j]=ans[j-1]^ans[j-2];
    }
    fin[i]=ans[n[i]];
  }
  for(i=0;i<t;i++)
  printf("%lld\n",fin[i]);
}


#include <stdio.h>

int main(void) {
  int t;
  scanf("%d",&t);
  long int a,b,n,fin[t],i,j;
  for(i=0;i<t;i++)
  {
    scanf("%ld%ld%ld",&a,&b,&n);
    int ans[n+1];
    ans[0]=a;
    ans[1]=b;
    for(j=2;j<=n;j++)
    {
      ans[j]=ans[j-1]^ans[j-2];
    }
    fin[i]=ans[n];
  }
  for(i=0;i<t;i++)
  printf("%ld\n",fin[i]);
}


#include <stdio.h>

int main(void) {
  int t;
  scanf("%d",&t);
  long long int a,b,n[t],fin[t],i,j;
  for(i=0;i<t;i++)
  {
    scanf("%lld%lld%lld",&a,&b,&n[i]);
    int ans[n[i]+1];
    ans[0]=a;
    ans[1]=b;
    for(j=2;j<=n[i];j++)
    {
      ans[j]=ans[j-1]^ans[j-2];
    }
    fin[i]=ans[n[i]];
  }
  for(i=0;i<t;i++)
  printf("%lld\n",fin[i]);
}


#include <stdio.h>

int main(void) {
  long long int a,b,n,t,i,j;
  scanf("%lld",&t);
  for(i=0;i<t;i++)
  {
    scanf("%lld%lld%lld",&a,&b,&n);
    int xor[n+1];
    xor[0]=a;
    xor[1]=b;
    for(j=2;j<=n;j++)
    {
      xor[j]=xor[j-1]^xor[j-2];
    }
    printf("\n");
    printf("%d",xor[n]);
    return 0;
  }
}


#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    ll a,b,n;
    cin >> a >> b >> n;
    if(n==0){
        cout << a << endl;
        return;
    }
    if(n==1){
        cout << b << endl;
        return;
    }
    ll ans = a^b;
    ll zero = a;
    ll one = b;
    ll cnt = 2;
    while(cnt<n){
        if(one==zero){
            break;
        }
        zero = one;
        one = ans;
        ans = zero^one;
        cnt++;
    }
    cout << ans<< endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    ll a,b,n;
    cin >> a >> b >> n;
    if(n==0){
        cout << a << endl;
        return;
    }
    if(n==1){
        cout << b << endl;
        return;
    }
    ll ans = a^b;
    ll zero = a;
    ll one = b;
    ll cnt = 2;
    while(cnt<n){
        zero = one;
        one = ans;
        ans = zero^one;
        cnt++;
    }
    cout << ans<< endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    ll a,b;
    int n;
    cin >> a >> b >> n;
    int s = max(2,n+1);
    vector<ll> f(s);
    f[0] = a;
    f[1] = b;
    int i;
    for(i=2;i<n+1;i++){
        f[i] = f[i-1]^f[i-2];
    }
    cout << f[n] << endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    ll a,b;
    int n;
    cin >> a >> b >> n;
    vector<ll> f(n+1);
    f[0] = a;
    f[1] = b;
    int i;
    for(i=2;i<n+1;i++){
        f[i] = f[i-1]^f[i-2];
    }
    cout << f[n] << endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll ans = a^b;
    ll x = n%3;
    if(x==0){
        cout << a << endl;
    }
    else if(x==1){
        cout << b << endl;
    }
    else{
        cout << ans << endl;
    }
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}


#include <iostream>
#include <algorithm>
#include <vector>

#define ll long long

using namespace std;

int main(){
    int t, n, a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%d%d%d", &a, &b, &n);
        vector<int>v(n+2);
        v[0] = a; v[1] = b;
        for(int i=2; i<=n; i++){
            v[i] = v[i-1]^v[i-2];
        }
        printf("%d\n", v[n]);
    }
}


#include <iostream>
#include <algorithm>
#include <vector>

#define ll long long

using namespace std;

int main(){
    int t, n, a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%d%d%d", &a, &b, &n);
        vector<int>v(n+1);
        v[0] = a; v[1] = b;
        for(int i=2; i<=n; i++){
            v[i] = v[i-1]^v[i-2];
        }
        printf("%d\n", v[n]);
    }
}


#include <bits/stdc++.h>
#define ll long long
const int N = 1e5+1;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int q, a, b, c, n;
    cin>>q;
    while(q--){
        cin>>a>>b>>n;
        c = a^b;
        if((n)%3 == 2){cout<<c<<endl;}
        else if((n)%3 == 1){cout<<b<<endl;}
        else {cout<<a<<endl;}
    }
}


#include <iostream>
#include <algorithm>
#include <vector>

#define ll long long

using namespace std;

int main(){
    int t, n, a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%d%d%d", &a, &b, &n);
        vector<int>c(n+1);
        c[0] = a; c[1] = b;
        for(int i=2; i<n+1; i++){c[i] = c[i-1] ^ c[i-2];}
        printf("%d\n", c[n]);
    }
}


#include <bits/stdc++.h>
#define ll long long
const int N = 1e5+1;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int q, a, b, n, tmp;
    cin>>q;
    while(q--){
        cin>>a>>b>>n;
        if(n == 0){cout<<a<<endl;continue;}
        for(int i=1; i<n; i++){
            tmp = b;
            b = a^b;
            a = tmp;
        }
        cout<<b<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>

#define ll long long

using namespace std;

int main(){
    int t, n, a, b;
    cin>>t;
    while(t--){
        cin>>a>>b>>n;
        vector<int>v(n+2);
        v[0] = a;
        v[1] = b;
        for(int i=2; i<=n; i++){
            v[i] = v[i-1]^v[i-2];
        }
        cout<<v[n]<<endl;
    }
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		ll c = (a^b);
				vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j <= n; ++j) {
					if (ans[j - 1] == b)
						ans[j] = c;
					else if (ans[j - 1] == a)
						ans[j] = a;
					else
						ans[j] = b;
				}
				cout << ans[n] << "\n";
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		ll c = (a^b);

		if ((n - 2) % 3 == 0)
			cout << c << "\n";
		else if (((n - 2) % 2 == 0 && (n - 2) % 3 == 0) || (n - 2 == 1))
			cout << a << "\n";
		else
			cout << b << "\n";

	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0)
			cout << a <<"\n";
		else {
			if (n == 1)
				cout << b << "\n";
			else {
				vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j <= n; ++j) {
					ans[j] = ans[j - 1] ^ ans[j - 2];
				}
				cout << ans[n] << "\n";
			}
		}
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		if (n % 2 == 0)
			cout << (a^b) << "\n";
		else if (n % 3 == 0)
			cout << a << "\n";
		else
			cout << b << "\n";
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		if (n % 2 == 0)
			cout << (a^b) << "\n";
		else if (n % 3 == 0)
			cout << b << "\n";
		else
			cout << a << "\n";
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
				/*vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j <= n; ++j) {
					ans[j] = (ans[j - 1] ^ ans[j - 2]);
				}*/
		cout << (a^b) << "\n";
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
ll f(ll x)
{
	if (x == 0)
		return a;
	if (x == 1)
		return b;
	f(x - 1);
}
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;
		if (n == 0)
			cout << a <<"\n";
		else {
			if (n == 1)
				cout << b << "\n";
			else
				cout << (f(n - 1) ^ f(n - 2)) << "\n";
		}
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		if (n % 2 == 0)
			cout << (a^b);
		else if (n % 3 == 0)
			cout << a;
		else
			cout << b;
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
ll f(ll x)
{
	if (x == 0)
		return a;
	if (x == 1)
		return b;
	return f(x - 1);
}
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0)
			cout << a <<"\n";
		else {
			if (n == 1)
				cout << b << "\n";
			else {
				vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j < n; ++j) {
					ans[j] = ans[j - 1] ^ ans[j - 2];
				}
				cout << (ans[n - 1] ^ ans[n - 2]);
			}
		}
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
ll f(ll x)
{
	if (x == 0)
		return a;
	if (x == 1)
		return b;
	return f(x - 1);
}
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0)
			cout << a <<"\n";
		else {
			if (n == 1)
				cout << b << "\n";
			else {
				vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j < n; ++j) {
					ans[j] = ans[j - 1] ^ ans[j - 2];
				}
				cout << (ans[n - 1] ^ ans[n - 2]) << "\n";
			}
		}
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
				/*vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j <= n; ++j) {
					ans[j] = (ans[j - 1] ^ ans[j - 2]);
				}*/
				cout << (a^b);
	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		ll c = (a^b);

		if ((n % 3) == 0)
			cout << a << "\n";
		else if ((n - 2) % 3 == 0)
			cout << c << "\n";
		else
			cout << b<<"\n";

	}
	return 0;
}


//
/*
╔╗╔╦═══╗
║║║║╔══╝
║╚╝║╚══╗
║╔╗║╔══╝
║║║║╚══╗
╚╝╚╩═══╝
╔╗╔╦╗╔╗
║║║║║║║
║╚╝║╚╝║
║╔╗╠═╗║
║║║║╔╝║
╚╝╚╝╚═╝
╔═══╦════╦══╗
╚══╗╠═╗╔═╣╔╗║
─╔═╝╝─║║─║║║║
─╚═╗╗─║║─║║║║
╔══╝║─║║─║╚╝║
╚═══╝─╚╝─╚══╝
╔═══╦══╦╗╔╗
║╔══╣╔╗║║║║
║╚══╣╚╝║╚╝║
║╔═╗║╔╗║╔╗║
║╚═╝║║║║║║║
╚═══╩╝╚╩╝╚╝
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
		ll c = (a^b);

		if ((n - 2) % 3 == 0)
			cout << c << "\n";
		else if (((n - 2) % 2 == 0 && (n - 2) % 3 == 0) || (n - 2 == 1))
			cout << b << "\n";
		else
			cout << a << "\n";

	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <numeric>
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
#pragma warning(disable : 4996) // ддя printf scanf
using namespace std;
ll a, b, n;
int main()
{
	IOS;
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {

		cin >> a >> b >> n;

		if (n == 0) {
			cout << a << "\n";
			continue;
		}
		if (n == 1) {
			cout << b << "\n";
			continue;
		}
				vector <ll> ans(n + 1);
				ans[0] = a;
				ans[1] = b;
				for (int j = 2; j <= n; ++j) {
					ans[j] = (ans[j - 1] ^ ans[j - 2]);
				}
				cout << ans[n] << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        int c=a^b;
        if(n%3==0)
            cout<<a<<endl;
        else if(n%3==1)
            cout<<b<<endl;
        else
            cout<<c<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        long long int arr[n];
        arr[0]=a;
        arr[1]=b;
        if(n==0)
            cout<<a<<endl;
        else if(n==1)
            cout<<b<<endl;
        else
        {
            for(long long int i=2; i<=n; i++)
            {
                arr[i]=arr[i-1]^arr[i-2];

            }
            cout<<arr[n]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        long longint arr[n];
        arr[0]=a;
        arr[1]=b;
        if(n==0)
            cout<<a<<endl;
        else if(n==1)
            cout<<b<<endl;
        else
        {
            for(long long int i=2; i<n; i++)
            {
                arr[i]=arr[i-1]^arr[n-2];

            }
            cout<<arr[n-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        int arr[n];
        arr[0]=a;
        arr[1]=b;
        if(n==0)
            cout<<a<<endl;
        else if(n==1)
            cout<<b<<endl;
        else
        {
            for(int i=3; i<=n; i++)
            {
                arr[i]=arr[i-1]^arr[n-2];

            }
            cout<<arr[n]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        if(n%3==0)
            cout<<a<<endl;
        else if(n%3==1)
            cout<<b<<endl;
        else
            cout<<a^b<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        long long int arr[n];
        arr[0]=a;
        arr[1]=b;
        if(n==0)
            cout<<a<<endl;
        else if(n==1)
            cout<<b<<endl;
        else
        {
            for(long long int i=2; i<n; i++)
            {
                arr[i]=arr[i-1]^arr[i-2];

            }
            cout<<arr[n-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    long long int a,b,n;
    for(int tt=0; tt<t; tt++)
    {
        cin>>a>>b>>n;
        long long int arr[n];
        arr[0]=a;
        arr[1]=b;
        if(n==0)
            cout<<a<<endl;
        else if(n==1)
            cout<<b<<endl;
        else
        {
            for(long long int i=2; i<n; i++)
            {
                arr[i]=arr[i-1]^arr[n-2];

            }
            cout<<arr[n-1]<<endl;
        }
    }
    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while(t--){
    long  long int a,b,n;
    cin>>a>>b>>n;
   long long  int f1=a;
    long long int f2=b;

    for(long long int i=2;i<=n;i++)
    {int c=f1^f2;
    f1=f2;
    f2=c;
    }
    if(n==0)cout<<f1<<endl;
    else
    cout<<f2<<endl;

    }
    return 0;
    }


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

int main(){
    int t;
    cin>>t;
    while(t--){
    int a,b,n;
    cin>>a>>b>>n;
    vector<int>f(n+1);
    f[0]=a;
    f[1]=b;

    for(int i=2;i<=n;i++)
    f[i]=f[i-1]^f[i-2];

    cout<<f[n]<<endl;

    }
    return 0;
    }


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

int main(){
    int t;
    cin>>t;
    while(t--){
    int a,b,n;
    cin>>a>>b>>n;
    vector<int>f;
    f[0]=a;
    f[1]=b;

    for(int i=2;i<=n;i++)
    f[i]=f[i-1]^f[i-2];
    cout<<f[n]<<endl;

    }
    return 0;
    }


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

int main(){
    int t;
    cin>>t;
    while(t--){
    long  long int a,b,n;
    cin>>a>>b>>n;
   long long  int f1=a;
    long long int f2=b;

    for(long long int i=2;i<=n;i++)
    {int c=f1^f2;
    f1=f2;
    f2=c;
    }

    cout<<f2<<endl;

    }
    return 0;
    }


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

int main(){
    int t;
    cin>>t;
    while(t--){
         int a,b,n;
         cin>>a>>b>>n;
         if(n%3==0)cout<<a<<endl;
         else if(n%3==1)cout<<b<<endl;
         else
         cout<<(a^b)<<endl;
    }
    return 0;
}


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

int main(){
    int t;
    cin>>t;
    while(t--){
    int a,b,n;
    cin>>a>>b>>n;
    vector<int>f(n+1);
    f[0]=a;
    f[1]=b;

    for(int i=2;i<=n;i++)
    f[i]=f[i-1]^f[i-2];
    cout<<f[n]<<endl;

    }
    return 0;
    }


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

int main(){
    int t;
    cin>>t;
    while(t--){
   long long  int a,b,n;
    cin>>a>>b>>n;
    vector<long long int>f(n+1);
    f[0]=a;
    f[1]=b;

    for(long long int i=2;i<=n;i++)
    f[i]=f[i-1]^f[i-2];
    cout<<f[n]<<endl;

    }
    return 0;
    }


#include<iostream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    vector <int> w;
    for(int i=0; i<t; i++){
        vector <int> v;
        int a,b,n;
        cin>>a>>b>>n;
        v.push_back(a);
        v.push_back(b);
        for(int j=2; j<=n; j++){
            v.push_back((v[j-1]^v[j-2]));
        }
        w.push_back(v[n]);
    }
    for(int i:w){
        cout<<i<<endl;
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    vector <long long int> w;
    for(int i=0; i<t; i++){
        vector <long long int> v;
        long long int a,b,n;
        cin>>a>>b>>n;
        v.push_back(a);
        v.push_back(b);
        v.push_back(a^b);
        int k = n%3;
        if(n<2){
            w.push_back(v[n]);
        }
        else{
            w.push_back(v[k]);
        }
    }
    for(long long int i:w){
        cout<<i<<endl;
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    vector <long long int> w;
    for(int i=0; i<t; i++){
        vector <long long int> v;
        long long int a,b,n;
        cin>>a>>b>>n;
        v.push_back(a);
        v.push_back(b);
        v.push_back(a^b);
        int k = n%3;
        w.push_back(v[k]);
    }
    for(long long int i:w){
        cout<<i<<endl;
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    vector <long long int> w;
    for(int i=0; i<t; i++){
        vector <long long int> v(2,0);
        long long int a,b,n;
        cin>>a>>b>>n;
        v[0] = a;
        v[1] = b;
        if(n<2){
            w.push_back(v[n]);
        }
        else{
        for(long long int j=2; j<=n; j++){
            long long int c = v[1];
            v[1] = (v[1]^v[0]);
            v[0] = c;
        }
        w.push_back(v[1]);
        }
    }
    for(long long int i:w){
        cout<<i<<endl;
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    vector <int> w;
    for(int i=0; i<t; i++){
        vector <int> v(2,0);
        int a,b,n;
        cin>>a>>b>>n;
        v[0] = a;
        v[1] = b;
        if(n<2){
            w.push_back(v[n]);
        }
        else{
        for(int j=2; j<=n; j++){
            int c = v[1];
            v[1] = (v[1]^v[0]);
            v[0] = c;
        }
        w.push_back(v[1]);
        }
    }
    for(int i:w){
        cout<<i<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {
        long long a,b,n;
        cin>>a>>b>>n;
        long long x[n];
        x[0]=a;
        x[1]=b;

        x[2]=x[0] ^ x[1];
        n=n%3;
        cout<<x[n]<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {
        long long a,b,n;
        cin>>a>>b>>n;
        long long x[n];
        x[0]=a;
        x[1]=b;

        x[0]=x[1] ^ x[2];
        n=n%3;
        cout<<x[n]<<endl;
    }
    return 0;
}


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

int main()
{
	long int n,a[3];
	int t,z;
	cin>>t;
	for(z=0;z<t;z++)
	{
		cin>>a[0]>>a[1]>>n;
		a[2]=a[0]^a[1];

		n=n%3;
		cout<<a[n]<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {
        long long a,b,n;
        cin>>a>>b>>n;
        long long x[n];
        x[0]=a;
        x[1]=b;
        if(n==0 ||n==1)
        {
            cout<<x[n]<<endl;
        }
        else
        {
            x[n]=x[n-1] + x[n-2];
            cout<<x[n]<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {
        long long a,b,n;
        cin>>a>>b>>n;
        long long x[n];
        x[0]=a;
        x[1]=b;
        if(n==0 ||n==1)
        {
            cout<<x[n]<<endl;
        }
        else
        {
            x[n]=x[n-1] ^ x[n-2];
            cout<<x[n]<<endl;
        }
    }
    return 0;
}


include<bits/stdc++.h>
using namespace std;
int main()
{
    int test,a,b,n;
    cin>>test;
    while(test--){
        cin>>a>>b>>n;
        switch (n%3){
            case 0:
              cout<<a<<endl;
              break;
            case 1:
              cout<<b<<endl;
              break;
            default:
              cout<<(a^b)<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define foi(n) for(int i=0;i<n;i++)
#define foj(n) for(int j=0;j<n;j++)
#define endl "\n"
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fixed(); cout << fixed << setprecision(20);
using namespace std;

//for declaring most used global variables and constants
const int mod=1e9+7;

//For Calculating nCr
template<typename T>
T nCr(T n, T r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    int  ans = 1,i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    } return ans;
}

//power optimized
template<typename T,typename T2>
T2 power(T x, T y)
{
    if (y == 0)  return 1;
    T2 res=power(x,y/2);
    if (y % 2)  return res*res*x;
    return res*res;
}

//return number of set bits in a given number
template<typename T>
int countSetBits(T n)
{
    int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    } return count;
}

//return true if number is prime
template<typename T>
bool isPrime(T n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n % 2 == 0 || n % 3 == 0)  return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
   return true;
}

//return true if string is palindrome
bool ispalindrome(string s)
{
    int len=s.length();
    foi(len){
        if(s[i]!=s[len-i-1])
        return false;
    }
    return true;
}

//adds two string which contains integer values.Used for Adding large Numbers
string AddString(string first,string second)
{
     // Before proceeding further, make sure length
    // of second is larger.
    if (first.length() > second.length())  swap(first, second);

    // Take an empty string for storing result
    string result = "";

    int n1 = first.length(), n2 = second.length();

    reverse(first.begin(), first.end());
    reverse(second.begin(), second.end());

    int carry = 0;
    for (int i=0; i<n1; i++) {
        int sum = ((first[i]-'0')+(second[i]-'0')+carry);
        result.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)  {
        int sum = ((second[i]-'0')+carry);
        result.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)  result.push_back(carry+'0');

    // reverse resultant string
    reverse(result.begin(), result.end());

    return result;
}

// Multiplies str1 and str2, and prints result.
string MultiplyString(string num1, string num2)
{
    int len1 = num1.size();
    int len2 = num2.size();
    if (len1 == 0 || len2 == 0)
    return "0";

    // will keep the result number in vector
    // in reverse order
    vector<int> result(len1 + len2, 0);

    // Below two indexes are used to find positions
    // in result.
    int i_n1 = 0;
    int i_n2 = 0;

    // Go from right to left in num1
    for (int i=len1-1; i>=0; i--)
    {
        int carry = 0;
        int n1 = num1[i] - '0';

        // To shift position to left after every
        // multiplication of a digit in num2
        i_n2 = 0;

        // Go from right to left in num2
        for (int j=len2-1; j>=0; j--)
        {
            // Take current digit of second number
            int n2 = num2[j] - '0';

            // Multiply with current digit of first number
            // and add result to previously stored result
            // at current position.
            int sum = n1*n2 + result[i_n1 + i_n2] + carry;

            // Carry for next iteration
            carry = sum/10;

            // Store result
            result[i_n1 + i_n2] = sum % 10;

            i_n2++;
        }

        // store carry in next cell
        if (carry > 0)
            result[i_n1 + i_n2] += carry;

        // To shift position to left after every
        // multiplication of a digit in num1.
        i_n1++;
    }

    // ignore '0's from the right
    int i = result.size() - 1;
    while (i>=0 && result[i] == 0)
    i--;

    // If all were '0's - means either both or
    // one of num1 or num2 were '0'
    if (i == -1)
    return "0";

    // generate the result string
    string s = "";

    while (i >= 0)
        s += to_string(result[i--]);

    return s;
}

//for string with space use std::getline(cin,string_name);
//***********************UVAISH ZAFRI*****************************
int32_t main() {
    fast(); fixed();
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

   int test;
   cin>>test;
   while(test--)
   {
      int a,b,n;
      cin>>a>>b>>n;
      if(a==b&&a==0)
      cout<<0<<endl;
      else if(a==b&&n%2==1)
      cout<<0<<endl;
      else if(a==b&&n%2==0)
      cout<<a<<endl;
      else if(n==0)
      cout<<a<<endl;
      else if(n==1)
      cout<<b<<endl;
      else{
          n-=1;
          while(n--){
              int x=a,y=b;
              b=x^b;
              a=y;
          }
          cout<<b<<endl;
      }
   }

  	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test,a,b,n;
    cin>>test;
    while(test--){
        cin>>a>>b>>n;
        switch (n%3){
            case 0:
              cout<<a<<endl;
              break;
            case 1:
              cout<<b<<endl;
              break;
            default:
              cout<<(a^b)<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define foi(n) for(int i=0;i<n;i++)
#define foj(n) for(int j=0;j<n;j++)
#define endl "\n"
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fixed(); cout << fixed << setprecision(20);
using namespace std;

//for declaring most used global variables and constants
const int mod=1e9+7;

//For Calculating nCr
template<typename T>
T nCr(T n, T r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    int  ans = 1,i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    } return ans;
}

//power optimized
template<typename T,typename T2>
T2 power(T x, T y)
{
    if (y == 0)  return 1;
    T2 res=power(x,y/2);
    if (y % 2)  return res*res*x;
    return res*res;
}

//return number of set bits in a given number
template<typename T>
int countSetBits(T n)
{
    int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    } return count;
}

//return true if number is prime
template<typename T>
bool isPrime(T n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n % 2 == 0 || n % 3 == 0)  return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
   return true;
}

//return true if string is palindrome
bool ispalindrome(string s)
{
    int len=s.length();
    foi(len){
        if(s[i]!=s[len-i-1])
        return false;
    }
    return true;
}

//adds two string which contains integer values.Used for Adding large Numbers
string AddString(string first,string second)
{
     // Before proceeding further, make sure length
    // of second is larger.
    if (first.length() > second.length())  swap(first, second);

    // Take an empty string for storing result
    string result = "";

    int n1 = first.length(), n2 = second.length();

    reverse(first.begin(), first.end());
    reverse(second.begin(), second.end());

    int carry = 0;
    for (int i=0; i<n1; i++) {
        int sum = ((first[i]-'0')+(second[i]-'0')+carry);
        result.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)  {
        int sum = ((second[i]-'0')+carry);
        result.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)  result.push_back(carry+'0');

    // reverse resultant string
    reverse(result.begin(), result.end());

    return result;
}

// Multiplies str1 and str2, and prints result.
string MultiplyString(string num1, string num2)
{
    int len1 = num1.size();
    int len2 = num2.size();
    if (len1 == 0 || len2 == 0)
    return "0";

    // will keep the result number in vector
    // in reverse order
    vector<int> result(len1 + len2, 0);

    // Below two indexes are used to find positions
    // in result.
    int i_n1 = 0;
    int i_n2 = 0;

    // Go from right to left in num1
    for (int i=len1-1; i>=0; i--)
    {
        int carry = 0;
        int n1 = num1[i] - '0';

        // To shift position to left after every
        // multiplication of a digit in num2
        i_n2 = 0;

        // Go from right to left in num2
        for (int j=len2-1; j>=0; j--)
        {
            // Take current digit of second number
            int n2 = num2[j] - '0';

            // Multiply with current digit of first number
            // and add result to previously stored result
            // at current position.
            int sum = n1*n2 + result[i_n1 + i_n2] + carry;

            // Carry for next iteration
            carry = sum/10;

            // Store result
            result[i_n1 + i_n2] = sum % 10;

            i_n2++;
        }

        // store carry in next cell
        if (carry > 0)
            result[i_n1 + i_n2] += carry;

        // To shift position to left after every
        // multiplication of a digit in num1.
        i_n1++;
    }

    // ignore '0's from the right
    int i = result.size() - 1;
    while (i>=0 && result[i] == 0)
    i--;

    // If all were '0's - means either both or
    // one of num1 or num2 were '0'
    if (i == -1)
    return "0";

    // generate the result string
    string s = "";

    while (i >= 0)
        s += to_string(result[i--]);

    return s;
}

//for string with space use std::getline(cin,string_name);
//***********************UVAISH ZAFRI*****************************
int32_t main() {
    fast(); fixed();
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

   int test;
   cin>>test;
   while(test--)
   {
      int a,b,n;
      cin>>a>>b>>n;
      if(n==0)
      cout<<a<<endl;
      else if(n==1)
      cout<<b<<endl;
      else{
          n-=1;
          while(n--){
              int x=a,y=b;
              b=x^b;
              a=y;
          }
          cout<<b<<endl;
      }
   }

  	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define foi(n) for(int i=0;i<n;i++)
#define foj(n) for(int j=0;j<n;j++)
#define endl "\n"
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fixed(); cout << fixed << setprecision(20);
using namespace std;

//for declaring most used global variables and constants
const int mod=1e9+7;

//For Calculating nCr
template<typename T>
T nCr(T n, T r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    int  ans = 1,i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    } return ans;
}

//power optimized
template<typename T,typename T2>
T2 power(T x, T y)
{
    if (y == 0)  return 1;
    T2 res=power(x,y/2);
    if (y % 2)  return res*res*x;
    return res*res;
}

//return number of set bits in a given number
template<typename T>
int countSetBits(T n)
{
    int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    } return count;
}

//return true if number is prime
template<typename T>
bool isPrime(T n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n % 2 == 0 || n % 3 == 0)  return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
   return true;
}

//return true if string is palindrome
bool ispalindrome(string s)
{
    int len=s.length();
    foi(len){
        if(s[i]!=s[len-i-1])
        return false;
    }
    return true;
}

//adds two string which contains integer values.Used for Adding large Numbers
string AddString(string first,string second)
{
     // Before proceeding further, make sure length
    // of second is larger.
    if (first.length() > second.length())  swap(first, second);

    // Take an empty string for storing result
    string result = "";

    int n1 = first.length(), n2 = second.length();

    reverse(first.begin(), first.end());
    reverse(second.begin(), second.end());

    int carry = 0;
    for (int i=0; i<n1; i++) {
        int sum = ((first[i]-'0')+(second[i]-'0')+carry);
        result.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)  {
        int sum = ((second[i]-'0')+carry);
        result.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)  result.push_back(carry+'0');

    // reverse resultant string
    reverse(result.begin(), result.end());

    return result;
}

// Multiplies str1 and str2, and prints result.
string MultiplyString(string num1, string num2)
{
    int len1 = num1.size();
    int len2 = num2.size();
    if (len1 == 0 || len2 == 0)
    return "0";

    // will keep the result number in vector
    // in reverse order
    vector<int> result(len1 + len2, 0);

    // Below two indexes are used to find positions
    // in result.
    int i_n1 = 0;
    int i_n2 = 0;

    // Go from right to left in num1
    for (int i=len1-1; i>=0; i--)
    {
        int carry = 0;
        int n1 = num1[i] - '0';

        // To shift position to left after every
        // multiplication of a digit in num2
        i_n2 = 0;

        // Go from right to left in num2
        for (int j=len2-1; j>=0; j--)
        {
            // Take current digit of second number
            int n2 = num2[j] - '0';

            // Multiply with current digit of first number
            // and add result to previously stored result
            // at current position.
            int sum = n1*n2 + result[i_n1 + i_n2] + carry;

            // Carry for next iteration
            carry = sum/10;

            // Store result
            result[i_n1 + i_n2] = sum % 10;

            i_n2++;
        }

        // store carry in next cell
        if (carry > 0)
            result[i_n1 + i_n2] += carry;

        // To shift position to left after every
        // multiplication of a digit in num1.
        i_n1++;
    }

    // ignore '0's from the right
    int i = result.size() - 1;
    while (i>=0 && result[i] == 0)
    i--;

    // If all were '0's - means either both or
    // one of num1 or num2 were '0'
    if (i == -1)
    return "0";

    // generate the result string
    string s = "";

    while (i >= 0)
        s += to_string(result[i--]);

    return s;
}

//for string with space use std::getline(cin,string_name);
//***********************UVAISH ZAFRI*****************************
int32_t main() {
    fast(); fixed();
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

   int test;
   cin>>test;
   while(test--)
   {
      int a,b,n;
      cin>>a>>b>>n;
      if(a==b&&a==0)
      cout<<0<<endl;
      else if(a==b&&n%2==0)
      cout<<0<<endl;
      else if(a==b&&n%2==1)
      cout<<a<<endl;
      else if(n==0)
      cout<<a<<endl;
      else if(n==1)
      cout<<b<<endl;
      else{
          n-=1;
          while(n--){
              int x=a,y=b;
              b=x^b;
              a=y;
          }
          cout<<b<<endl;
      }
   }

  	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       int a,b,n;
       cin>>a>>b>>n;
       int x=a^b;
       if(n==0){
           cout<<a;
           continue;
       }
       if(n==1){
           cout<<b<<endl;
           continue;
       }

       if(n!=0 && (n-2)%3==0){
           cout<<x<<endl;
           continue;
       }

       if(n%3==0){
           cout<<a<<endl;
           continue;
       }
       else{
           cout<<b<<endl;
           continue;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int T;
   cin>>T;
   for(int i =0;i<T;i++){
       int a,b,n,arr[1000000000];
       cin>>a>>b>>n;
       arr[0]=a;
       arr[1]=b;
       for(int j=2;j<n;j++){
           arr[j]=arr[j-1]^arr[j-2];
       }
       cout<<arr[n];
   }
   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       int a,b,n;
       int x=a^b;
       cin>>a>>b>>n;
       if(n==0){
           cout<<a;
       }
       if(n==1){
           cout<<b;
       }
       if((n-2)%n==0){
           cout<<x;
       }
       if(n%3==0){
           cout<<a;
       }
       else{
           cout<<b;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       int a,b,n;
       cin>>a>>b>>n;
       int x=a^b;
       if(n==0){
           cout<<a;
       }
       if(n==1){
           cout<<b<<endl;
       }

       if(n!=0 && (n-2)%3==0){
           cout<<x<<endl;
       }

       if(n%3==0){
           cout<<a<<endl;
       }
       else{
           cout<<b<<endl;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   for(int i=0;i<T;i++){
       int a,b,n;
       int x=a^b;
       cin>>a>>b>>n;
       if((n-2)%3==0){
           cout<<x;
       }
       if(n%3==0){
           cout<<a;
       }
       else{
           cout<<b;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   for(int i=0;i<T;i++){
       int a,b,n;
       int x=a^b;
       cin>>a>>b>>n;
       if(n==0){
           cout<<a;
       }
       if(n==1){
           cout<<b;
       }
       if((n-2)%n==0){
           cout<<x;
       }
       if(n%3==0){
           cout<<a;
       }
       else{
           cout<<b;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       int a,b,n;
       cin>>a>>b>>n;
       int x=a^b;
       if(n==0){
           cout<<a;
       }
       if(n==1){
           cout<<b<<endl;
       }

       if(n!=0 && (n-2)%n==0){
           cout<<x<<endl;
       }

       if(n%3==0){
           cout<<a<<endl;
       }
       else{
           cout<<b<<endl;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int T,arr[1000];
   cin>>T;
   for(int i =0;i<T;i++){
       int a,b,n;
       cin>>a>>b>>n;
       arr[0]=a;
       arr[1]=b;
       for(int j=2;j<n;j++){
           arr[j]=arr[j-1]^arr[j-2];
       }
       cout<<arr[n];
   }
   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       int a,b,n;
       int x=a^b;
       cin>>a>>b>>n;
       if(n==0){
           cout<<a;
       }
       if(n==1){
           cout<<b;
       }
       if(n!=0){
         if((n-2)%n==0){
           cout<<x;
       }
       }
       if(n%3==0){
           cout<<a;
       }
       else{
           cout<<b;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T,;
   for(int i=0;i<T;i++){
       int a,b,n;
       int x=a^b;
       cin>>a>>b>>n;
       if((n-2)%n==0){
           cout<<x;
       }
       if(n%3==0){
           cout<<a;
       }
       else{
           cout<<b;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   for(int i=0;i<T;i++){
       int a,b,n;
       int x=a^b;
       cin>>a>>b>>n;
       if((n-2)%n==0){
           cout<<x;
       }
       if(n%3==0){
           cout<<a;
       }
       else{
           cout<<b;
       }
   }

   return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       int a,b,n;
       cin>>a>>b>>n;
       int x=a^b;
       if(n==0){
           cout<<a<<endl;
           continue;
       }
       if(n==1){
           cout<<b<<endl;
           continue;
       }

       if(n!=0 && (n-2)%3==0){
           cout<<x<<endl;
           continue;
       }

       if(n%3==0){
           cout<<a<<endl;
           continue;
       }
       else{
           cout<<b<<endl;
           continue;
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
#define ll long long int

int main()
{

ll t;
cin>>t;

	while(t--)
	{
		ll a,b,n;
		cin>>a>>b>>n;

		if(n==0)
		{
			cout<<a<<endl;
		}
		else if(n==1)
		{
			cout<<b<<endl;

		}
		else if(n%2==0)
		{
			cout<<(a^b)<<endl;
		}
		else
		{
			cout<<"0"<<endl;
		}
	}

return 0;
}


#include<iostream>
using namespace std;
#define ll long long int

int main()
{

ll t;
cin>>t;

	while(t--)
	{
		ll a,b,n;
		cin>>a>>b>>n;

		if(n==0)
		{
			cout<<a<<endl;
		}
		else if(n==1)
		{
			cout<<b<<endl;

		}
		else
		{
			ll ans=0;
			for(ll i=2;i<=n;i++)
			{
				ans=a^b;
				a=b;
				b=ans;
			}
			cout<<ans<<endl;
		}
	}

return 0;
}


#include<iostream>
using namespace std;
#define ll long long int

int main()
{

ll t;
cin>>t;

	while(t--)
	{
		ll a,b,n;
		cin>>a>>b>>n;

		if(n==0)
		{
			cout<<a<<endl;
		}
		else if(n==1)
		{
			cout<<b<<endl;

		}
		else if((n-1)%3==0)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<(a^b)<<endl;
		}
	}

return 0;
}


#include<iostream>
using namespace std;
#define ll long long int

int main()
{

ll t;
cin>>t;

	while(t--)
	{
		ll a,b,n;
		cin>>a>>b>>n;

		if(n==0)
		{
			cout<<a<<endl;
		}
		else if(n==1)
		{
			cout<<b<<endl;

		}
		else if(a==b)
		{
			if(n%2==1)
			{
				cout<<0<<endl;
			}
			else
			{
				cout<<a<<endl;
			}
		}
		else
		{
			ll ans=0;
			for(ll i=2;i<=n;i++)
			{
				ans=a^b;
				a=b;
				b=ans;
			}
			cout<<ans<<endl;
		}
	}

return 0;
}


#include<iostream>
using namespace std;
#define ll long long int

int main()
{

ll t;
cin>>t;

	while(t--)
	{
		ll a,b,n;
		cin>>a>>b>>n;

		if(n%3==0)
		{
			cout<<a<<endl;
		}
		else if(n%3==1)
		{
			cout<<b<<endl;
		}
		else
		{
			cout<<(a^b)<<endl;
		}
	}

return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;
long long n, i, sum, a, b;

int main()
{
    cin >> n;

    while(n--) {
        cin >> a >> b >> i;
        if(i == 0)
            cout << a;
        else
            if(i == 1)
                cout << b;
            else {
                if(i % 2 == 0) {
                    cout << (a ^ b) << endl;
                }
                else
                    if(i % 3 == 0) {
                        cout << a << endl;
                    }
                    else
                        cout << b << endl;
            }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;
long long n, i, sum, a, b;

int main()
{
    cin >> n;

    while(n--) {
        cin >> a >> b >> i;
        if(i == 0)
            cout << a << endl;
        else
            if(i == 1)
                cout << b << endl;
            else {
                if(i % 2 == 0) {
                    cout << (a ^ b) << endl;
                }
                else
                    if(i % 3 == 0) {
                        cout << a << endl;
                    }
                    else
                        cout << b << endl;
            }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;
long long n, i, sum, a, b;

int main()
{
    cin >> n;

    while(n--) {
        cin >> a >> b >> i;
        if(a == b)
            cout << a;
        else {
            if(i == 0)
                cout << a << endl;
            else
                if(i == 1)
                    cout << b << endl;
                else {
                    if(i % 2 == 0) {
                        cout << (a ^ b) << endl;
                    }
                    else
                        if(i % 3 == 0) {
                            cout << a << endl;
                        }
                        else
                            cout << b << endl;
                }
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;
long long n, i, sum, a, b;

int main()
{
    cin >> n;

    while(n--) {
        cin >> a >> b >> i;
        if(a == b)
            cout << a << endl;
        else {
            if(i == 0)
                cout << a << endl;
            else
                if(i == 1)
                    cout << b << endl;
                else {
                    if(i % 2 == 0) {
                        cout << (a ^ b) << endl;
                    }
                    else
                        if(i % 3 == 0) {
                            cout << a << endl;
                        }
                        else
                            cout << b << endl;
                }
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;
long long n, i, sum, a, b;

int main()
{
    cin >> n;

    while(n--) {
        cin >> a >> b >> i;
        if(i % 3 == 0)
            cout << a << endl;
        else
            if(i % 3 == 1)
                cout << b << endl;
            else
                cout << (a ^ b) << endl;
    }

    return 0;
}


///                         .
///                     /   ))     |\         )               ).
///               c++. (\  ( `.    / )  (\   ( `.     ).     ( (
///               | |   ))  ) )   ( (   `.`.  ) )    ( (      ) )
///               | |  ( ( / _..----.._  ) | ( ( _..----.._  ( (
/// ,-.           | |---) V.'-------.. `-. )-/.-' ..------ `--) \._
/// | /===========| |  (   |      ) ( ``-.`\/'.-''           (   ) ``-._
/// | | / / / / / | |--------------------->  <-------------------------_>=-
/// | \===========| |                 ..-'./\.`-..                _,,-'
/// `-'           | |-------._------''_.-'----`-._``------_.-----'
///               | |         ``----''            ``----''
///               | |
///               c++`

///██╗ ██████╗ ██╗    ██████╗  ██████╗  ██████╗   ██████╗
///██║██╔═══██╗██║    ╚════██╗██╔═████╗ ╚════██╗ ██╔═████╗
///██║██║   ██║██║     █████╔╝██║██╔██║  █████╔╝ ██║██╔██║
///██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██╔═══╝  ████╔╝██║
///██║╚██████╔╝██║    ███████╗╚██████╔╝ ███████╗ ╚██████╔╝
///╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚══════╝  ╚═════╝

#include<bits/stdc++.h>
#include<fstream>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define quluq return 0;
#define Zohiri_dzd
#define Mekh
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
deque <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st ;
deque <double> sd , ds ;
ll a , b , c , d , e , f , cnt , ans , r , n , l , x , y ;
ld q , t , cnt1 , cnt2 ;
string g , h , w , o , m , s ;
char z , u ;
bool re , rt ;
vector<pair < ll , ll > > pr , rp , pp ;
map < pair < char , char > , ll > aw , wa ;

int main ()
{
    bzbz
    mlojins
    Qulukh
    Mekh
    CODER
    Zohiri_dzd
    Black_star
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Author :: Murtazoev Alijon
    cin >> f ;
    for (ll j = 0 ; j < f ; j ++ )
    {
        cin >> a >> b >> c ;
        v.clear();
        v.pb(a) ;
        v.pb(b) ;
        for (ll i = 2 ; i <= c ; i ++ )
            v.pb(v[i - 1] ^ v[i - 2]) ;
        cout << v[c] ;
    }
}
///Mmavl studios
///Eco students


///                         .
///                     /   ))     |\         )               ).
///               c++. (\  ( `.    / )  (\   ( `.     ).     ( (
///               | |   ))  ) )   ( (   `.`.  ) )    ( (      ) )
///               | |  ( ( / _..----.._  ) | ( ( _..----.._  ( (
/// ,-.           | |---) V.'-------.. `-. )-/.-' ..------ `--) \._
/// | /===========| |  (   |      ) ( ``-.`\/'.-''           (   ) ``-._
/// | | / / / / / | |--------------------->  <-------------------------_>=-
/// | \===========| |                 ..-'./\.`-..                _,,-'
/// `-'           | |-------._------''_.-'----`-._``------_.-----'
///               | |         ``----''            ``----''
///               | |
///               c++`

///██╗ ██████╗ ██╗    ██████╗  ██████╗  ██████╗   ██████╗
///██║██╔═══██╗██║    ╚════██╗██╔═████╗ ╚════██╗ ██╔═████╗
///██║██║   ██║██║     █████╔╝██║██╔██║  █████╔╝ ██║██╔██║
///██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██╔═══╝  ████╔╝██║
///██║╚██████╔╝██║    ███████╗╚██████╔╝ ███████╗ ╚██████╔╝
///╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚══════╝  ╚═════╝

#include<bits/stdc++.h>
#include<fstream>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define quluq return 0;
#define Zohiri_dzd
#define Mekh
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
deque <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st ;
deque <double> sd , ds ;
ll a , b , c , d , e , f , cnt , ans , r , n , l , x , y ;
ld q , t , cnt1 , cnt2 ;
string g , h , w , o , m , s ;
char z , u ;
bool re , rt ;
vector<pair < ll , ll > > pr , rp , pp ;
map < pair < char , char > , ll > aw , wa ;

int main ()
{
    bzbz
    mlojins
    Qulukh
    Mekh
    CODER
    Zohiri_dzd
    Black_star
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Author :: Murtazoev Alijon
    cin >> f ;
    for (ll j = 0 ; j < f ; j ++ )
    {
        cin >> a >> b >> c ;
        v.clear();
        v.pb(a) ;
        v.pb(b) ;
        for (ll i = 2 ; i <= c ; i ++ )
            v.pb(v[i - 1] ^ v[i - 2]) ;
        cout << v[c] << endl ;
    }
}
///Mmavl studios
///Eco students


///                         .
///                     /   ))     |\         )               ).
///               c++. (\  ( `.    / )  (\   ( `.     ).     ( (
///               | |   ))  ) )   ( (   `.`.  ) )    ( (      ) )
///               | |  ( ( / _..----.._  ) | ( ( _..----.._  ( (
/// ,-.           | |---) V.'-------.. `-. )-/.-' ..------ `--) \._
/// | /===========| |  (   |      ) ( ``-.`\/'.-''           (   ) ``-._
/// | | / / / / / | |--------------------->  <-------------------------_>=-
/// | \===========| |                 ..-'./\.`-..                _,,-'
/// `-'           | |-------._------''_.-'----`-._``------_.-----'
///               | |         ``----''            ``----''
///               | |
///               c++`

///██╗ ██████╗ ██╗    ██████╗  ██████╗  ██████╗   ██████╗
///██║██╔═══██╗██║    ╚════██╗██╔═████╗ ╚════██╗ ██╔═████╗
///██║██║   ██║██║     █████╔╝██║██╔██║  █████╔╝ ██║██╔██║
///██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██╔═══╝  ████╔╝██║
///██║╚██████╔╝██║    ███████╗╚██████╔╝ ███████╗ ╚██████╔╝
///╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚══════╝  ╚═════╝

#include<bits/stdc++.h>
#include<fstream>
#include "windows.h"
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define quluq return 0;
#define Zohiri_dzd
#define Mekh
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <char , ll> mp , pm ;
map <ll , ll> hs ;
deque <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st ;
deque <double> sd , ds ;
ll a , b , c , d , e , f , cnt , ans , r , n , l , x , y ;
ld q , t , cnt1 , cnt2 ;
string g , h , w , o , m , s ;
char z , u ;
bool re , rt ;
vector<pair < string , ll > > pr , rp , pp ;
map < pair < char , char > , ll > aw , wa ;

int main ()
{
    bzbz
    mlojins
    Qulukh
    Mekh
    CODER
    Zohiri_dzd
    Black_star
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Author :: Murtazoev Alijon
    cin >> a ;
    for (ll i = 0 ; i < a ; i ++ )
    {
        cin >> b >> c >> d ;
        if ( d == 0 )
            cout << b << endl ;
        else if ( d == 1 )
            cout << c << endl ;
        else if (d % 2 == 0)
            cout << (b^c) << endl ;
        else
        {
            cnt = b ^ c;
            cnt ^= d;
            cout << cnt << endl ;
        }
    }
}
///Mmavl studios
///Eco students


///                         .
///                     /   ))     |\         )               ).
///               c++. (\  ( `.    / )  (\   ( `.     ).     ( (
///               | |   ))  ) )   ( (   `.`.  ) )    ( (      ) )
///               | |  ( ( / _..----.._  ) | ( ( _..----.._  ( (
/// ,-.           | |---) V.'-------.. `-. )-/.-' ..------ `--) \._
/// | /===========| |  (   |      ) ( ``-.`\/'.-''           (   ) ``-._
/// | | / / / / / | |--------------------->  <-------------------------_>=-
/// | \===========| |                 ..-'./\.`-..                _,,-'
/// `-'           | |-------._------''_.-'----`-._``------_.-----'
///               | |         ``----''            ``----''
///               | |
///               c++`

///██╗ ██████╗ ██╗    ██████╗  ██████╗  ██████╗   ██████╗
///██║██╔═══██╗██║    ╚════██╗██╔═████╗ ╚════██╗ ██╔═████╗
///██║██║   ██║██║     █████╔╝██║██╔██║  █████╔╝ ██║██╔██║
///██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██╔═══╝  ████╔╝██║
///██║╚██████╔╝██║    ███████╗╚██████╔╝ ███████╗ ╚██████╔╝
///╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚══════╝  ╚═════╝

#include<bits/stdc++.h>
#include<fstream>
#include "windows.h"
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define quluq return 0;
#define Zohiri_dzd
#define Mekh
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <char , ll> mp , pm ;
map <ll , ll> hs ;
deque <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st ;
deque <double> sd , ds ;
ll a , b , c , d , e , f , cnt , ans , r , n , l , x , y ;
ld q , t , cnt1 , cnt2 ;
string g , h , w , o , m , s ;
char z , u ;
bool re , rt ;
vector<pair < string , ll > > pr , rp , pp ;
map < pair < char , char > , ll > aw , wa ;

int main ()
{
    bzbz
    mlojins
    Qulukh
    Mekh
    CODER
    Zohiri_dzd
    Black_star
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Author :: Murtazoev Alijon
    cin >> a ;
    for (ll i = 0 ; i < a ; i ++ )
    {
        cin >> b >> c >> d ;
        if( !(d % 3) )
            cout << b << endl;
            else if( d % 3 == 1 )
                cout << c << endl;
            else
                cout << (b^c) << endl;
    }
}
///Mmavl studios
///Eco students


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
using namespace std;

typedef unsigned long long ULL;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);

    double h,c,d,n;
    double mini;
    int hh,mm;
    double sum1,sum2;
    cin>>hh>>mm;
    cin>>h>>d>>c>>n;
    int time,timestart,timeend;
    timestart=20*60;
    time=hh*60+mm;
    if(time>=timestart)
        mini=int(h/n+0.5)*c*0.8;
    else
    {
        sum1=int(((timestart-time+h)*d)/n+0.5)*c*0.8;
        sum2=int(h/n+0.5)*c;
//        cout<<ceil(h/n);
        mini=min(sum1,sum2);
    }

    printf("%.4f\n",mini);
//    cout<<int(h/n+0.5);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
using namespace std;

typedef unsigned long long ULL;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);

    double h,c,d,n;
    double mini;
    int hh,mm;
    double sum1,sum2;
    cin>>hh>>mm;
    cin>>h>>d>>c>>n;
    int time,timestart,timeend;
    timestart=20*60;
    timeend=24*60-1;
    time=hh*60+mm;
    if(time>=timestart)
        mini=int(h/n+0.5)*c*0.8;
    else
    {
        sum1=int(((timestart-time)*d+h)/n+0.5)*c*0.8;
        sum2=int(h/n+0.5)*c;
//        cout<<ceil(h/n);
        mini=min(sum1,sum2);
    }

    printf("%.4f\n",mini);
//    cout<<int(h/n+0.5);
    return 0;
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define sgn(x) (((x)>eps)-((x)<-eps))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int t, a, b, c, d;

	scanf("%1d%1d %1d%1d", &a, &b, &c, &d);

	INT H, D, C, N;

	cin>>H>>D>>C>>N;

	t=(a*10+b)*60+c*10+d;

	if(t>=1200) {

		printf("%.5lf\n", .8*C*((H+N-1)/N));

		return 0;

	}

	DO ans=.8*C*((H+(1200-t)*D+N-1)/N);

	DO mx=C*((H+N-1)/N);

	printf("%.5lf\n", min(ans, mx));

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define sgn(x) (((x)>eps)-((x)<-eps))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int t, a, b, c, d;

	scanf("%1d%1d %1d%1d", &a, &b, &c, &d);

	INT H, D, C, N;

	cin>>H>>D>>C>>N;

	t=(a*10+b)*60+c*10+d;

	if(t>=1200) {

		printf("%.5lf\n", .8*C*((H+N-1)/N));

		return 0;

	}

	DO ans=.8*C*((H+(1200-t)*C+N-1)/N);

	DO mx=C*((H+N-1)/N);

	printf("%.5lf\n", min(ans, mx));

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int hh,mm,H,D,C,N;

	cin>>hh>>mm>>H>>D>>C>>N;

	if(hh>=20){

		int a=H/N;

		if(a*N!=H) a++;

		cout<<a<<' '<<C<<endl;

		double cost=(double)a*C*4/5;

		printf("%.4lf",cost);

	}

	else{

		int time=60*(20-hh)-mm;

		int b=H+D*time;

		int a=b/N;

		if(a*N!=b) a++;

		double costa=(double)a*C*4/5;

		int aa=H/N;

		if(aa*N!=H) aa++;

		double cost=(double)aa*C;

		double x=min(costa,cost);

		printf("%.4lf",x);

	}

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define sgn(x) (((x)>eps)-((x)<-eps))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int t, a, b, c, d;

	scanf("%1d%1d %1d%1d", &a, &b, &c, &d);

	INT H, D, C, N;

	gn(H, D);

	gn(C, N);

	t=(a*10+b)*60+c*10+d;

	if(t>=1200) {

		printf("%.5lf\n", .8*C*((H+N-1)/N));

		return 0;

	}

	DO ans=.8*C*((H+1200-t+N-1)/N);

	DO mx=0;

	for(int i=t; i<1200 && H>0; i++) {

		H-=N;

		mx+=C;

	}

	while(H>0) {

		H-=N;

		mx+=0.8*C;

	}

	printf("%.5lf\n", max(ans, mx));

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int hh,mm,H,D,C,N;

	cin>>hh>>mm>>H>>D>>C>>N;

	if(hh>=20){

		int a=H/N;

		if(a*N!=H) a++;

		double cost=(double)a*C*4/5;

		printf("%.4lf",cost);

	}

	else{

		int time=60*(20-hh)-mm;

		int b=H+D*time;

		int a=b/N;

		if(a*N!=b) a++;

		double costa=(double)a*C*4/5;

		int aa=H/N;

		if(aa*N!=H) aa++;

		double cost=(double)aa*C;

		double x=min(costa,cost);

		printf("%.4lf",x);

	}

	return 0;

}


#include <iostream>
#include <cmath>

using namespace std;

void printn(double a)
{
    //cout << floor(a);
    //cout << '.';
    //cout << (a-floor(a))*10000;
    cout << (floor(a*10000)/10000);
    //cout << a;
}

int main()
{
    double th, m, h, d, c, n;
    cin >> th >> m >> h >> d >> c >> n;

    double t = th*60 + m;
    double dt = 20*60 - t;
    double r = ceil(h/n);

    double m1 =  r*c;
    double m2;
    if(dt > 0)
        m2 = c * (0.8) * (r + dt*d);
    else
        m2 = c * (0.8) * r;

    printn(min(m1, m2));
    //cout << endl << r ;

    return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

void printn(double a)
{
    //cout << floor(a);
    //cout << '.';
    //cout << (a-floor(a))*10000;
    cout << (floor(a*10000)/10000);
    //cout << a;
}

int main()
{
    double th, m, h, d, c, n;
    cin >> th >> m >> h >> d >> c >> n;

    double t = th*60 + m;
    double dt = 20*60 - t;
    double r = ceil(h/n);

    double m1 =  r*c;
    double m2;
    if(dt > 0)
        m2 = c * (0.8) * (ceil((h+dt*d)/n));
    else
        m2 = c * (0.8) * r;

    printn(min(m1, m2));
    //cout << endl << r ;

    return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

void printn(double a)
{
    //cout << floor(a);
    //cout << '.';
    //cout << (a-floor(a))*10000;
    cout << (floor(a*10000)/10000);
}

int main()
{
    double th, m, h, d, c, n;
    cin >> th >> m >> h >> d >> c >> n;

    int t = th*60 + m;
    int dt = 20*60 - t;
    int r = ceil(h/n);

    double m1 =  r*c;
    double m2;
    if(dt > 0)
        m2 = (double)c * (0.8) * ((double)r + dt*d);
    else
        m2 = m1;

    printn(min(m1, m2));
    //cout << endl << r ;

    return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

void printn(double a)
{
    //cout << floor(a);
    //cout << '.';
    //cout << (a-floor(a))*10000;
    //cout << (floor(a*10000)/10000);
    cout << a;
}

int main()
{
    double th, m, h, d, c, n;
    cin >> th >> m >> h >> d >> c >> n;

    int t = th*60 + m;
    int dt = 20*60 - t;
    int r = ceil(h/n);

    double m1 =  r*c;
    double m2;
    if(dt > 0)
        m2 = (double)c * (0.8) * ((double)r + dt*d);
    else
        m2 = m1;

    printn(min(m1, m2));
    //cout << endl << r ;

    return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

void printn(double a)
{
    //cout << floor(a);
    //cout << '.';
    //cout << (a-floor(a))*10000;
    //cout << (floor(a*10000)/10000);
    cout << a;
}

int main()
{
    double th, m, h, d, c, n;
    cin >> th >> m >> h >> d >> c >> n;

    int t = th*60 + m;
    int dt = 20*60 - t;
    int r = ceil(h/n);

    double m1 =  r*c;
    double m2;
    if(dt > 0)
        m2 = (double)c * (0.8) * ((double)r + dt*d);
    else
        m2 = c * (0.8) * r;

    printn(min(m1, m2));
    //cout << endl << r ;

    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
    int hh,mm,h,d,c,n,t;
    cin >>hh;
    cin >>mm;
    cin >>h;
    cin >>d;
    cin >>c;
    cin >>n;
    cout.precision(4);
    if (hh>=20)
        cout <<round((double)h/n)*(double)c*0.8;
    else{
        t=(20-hh)*60+mm;
        double m1=round(((double)h+(double)(t*d))/n)*(double)c*0.8;
        double m2=round((double)h/n)*(double)c;
        if (m1<m2)
            cout <<m1;
        else
            cout <<m2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
    int hh,mm,h,d,c,n,t;
    cin >>hh;
    cin >>mm;
    cin >>h;
    cin >>d;
    cin >>c;
    cin >>n;
    cout.precision(4);
    if (hh>=20)
        cout <<round((double)h/n)*(double)c*0.8;
    else{
        t=(20-hh)*60+mm;
        double m1=round((double)h+(double)(t*d)/n)*(double)c*0.8;
        double m2=round((double)h/n)*(double)c;
        if (m1<m2)
            cout <<m1;
        else
            cout <<m2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>      // std::setprecision

using namespace std;

int main()
{
    int hh,mm,h,d,c,n,t;
    cin >>hh;
    cin >>mm;
    cin >>h;
    cin >>d;
    cin >>c;
    cin >>n;
    if (hh>=20)
        cout <<std::setprecision (4)<<round((double)h/n)*(double)c*0.8;
    else{
        t=(20-hh)*60+60-mm-1;
        double m1=round(((double)h+(double)(t*d))/n)*(double)c*0.8;
        double m2=round((double)h/n)*(double)c;
        if (m1<m2)
            cout <<std::setprecision (4)<<m1;
        else
            cout <<std::setprecision (4)<<m2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>      // std::setprecision

using namespace std;

int main()
{
    int hh,mm,h,d,c,n,t;
    cin >>hh;
    cin >>mm;
    cin >>h;
    cin >>d;
    cin >>c;
    cin >>n;
    cout.precision(4);
    if (hh>=20)
        cout <<fixed<<ceil((float)h/n)*(float)c*0.8;
    else{
        t=(19-hh)*60+60-mm;
        float m1=ceil(((float)h+(float)(t*d))/n)*(float)c*0.8;
        float m2=ceil((float)h/n)*(float)c;

        if (m1<m2)
            cout <<fixed<<m1;
        else
            cout <<fixed<<m2;
    }

    return 0;
}