#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
void solve(){
int x;
cin>>x;
int g=0,sum,mx=0,ans=0;
for(int y=x-1;y>=1;y--){
g=gcd(x,y);
sum=y+g;
if(sum>mx){
ans=y;
mx=sum;
}
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin>>t;
//t=1;
while(t--)solve();
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n,m;
cin>>n>>m;
string s1,s2;
cin>>s1>>s2;
int i=0,j=0;
while(i<n){
if(j==m)break;
if(s1[i]==s2[j])j++,i++;
else j++;
}
cout<<i<<endl;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin>>t;
//t=1;
while(t--)solve();
return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
int n;
cin>>n;
vector<int>a(n),b(n+1);
for(int i=1;i<n;i++)cin>>a[i];
b[1]=11451419;
for(int i=2;i<=n;i++){
b[i]=b[i-1]+a[i-1];
}
for(int i=1;i<=n;i++)cout<<b[i]<<' ';
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin>>t;
//t=1;
while(t--)solve();
return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e7+10;
int p[N],w[N],n,k;
int f(int x){
int pre=0,ans=w[x]*k;
for(int i=1;i<=min(n,k);i++){
pre+=w[x];
x=p[x];
ans=max(ans,pre+w[x]*(k-i));
}
return ans;
}
void solve(){
int x,y;
cin>>n>>k>>x>>y;
for(int i=1;i<=n;i++)cin>>p[i];
for(int i=1;i<=n;i++)cin>>w[i];
int a=f(x),b=f(y);
if(a>b)cout<<"Bodya"<<endl;
else if(a<b)cout<<"Sasha"<<endl;
else cout<<"Draw"<<endl;
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin>>t;
//t=1;
while(t--)solve();
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
cout<<1<<' '<<1<<endl;
cout<<1<<' '<<2<<endl;
for(int i=3;i<=n;i++)cout<<i<<' '<<i<<endl;
cout<<endl;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin>>t;
//t=1;
while(t--)solve();
return 0;
}