ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

#include<algorithm>

using namespace std;

#define int long long

#define pub push_back  

#define pob pop_back  

#define cin(v) for(auto &val:v) cin >> val  

#define cout(v) for(auto &val:v) cout <<val <<" ";cout << endl;

#define vi vector<int>

#define all(v) v.begin(),v.end()

#define endl "\n"

// Dont't get stuck on one approach ::

const int M=1e9+7;

int binexp(int a,int b){

  int ans=1;

  while(b){

    if(b&1){

      ans=(ans*a)%M;

    }

    a=(a*a)%M;

    b>>=1;

  }

  return ans;

}

signed main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  int t;

  cin >> t;

  while(t--){

    int n,x,y;

    cin >> n;

    cin>> x >> y;

    vi ans(n+1,0);

    for(int i=1;i<=n;++i){

        if(!(i&1)) ans[i]=1;

    }

    if(n&1)

    ans[n]=2;

    if((x&1)==(y&1)){

        ans[y]=2;

    }

    if(n&1){

        if(y==n-1){

            ans[n]=1;

        }

        else if(y==n-2){

            ans[n-1]=0;

            ans[n]=1;

        }

    }

    for(int i=1;i<=n;++i){

        cout << ans[i] << " ";

    }

    cout << endl;

    }

}



Submission (verdict: Accepted):
#include<bits/stdc++.h>

#include<algorithm>

using namespace std;

#define int long long

#define pub push_back  

#define pob pop_back  

#define cin(v) for(auto &val:v) cin >> val  

#define cout(v) for(auto &val:v) cout <<val <<" ";cout << endl;

#define vi vector<int>

#define all(v) v.begin(),v.end()

#define endl "\n"

// Dont't get stuck on one approach ::

const int M=1e9+7;

int binexp(int a,int b){

  int ans=1;

  while(b){

    if(b&1){

      ans=(ans*a)%M;

    }

    a=(a*a)%M;

    b>>=1;

  }

  return ans;

}

signed main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  int t;

  cin >> t;

  while(t--){

    int n,x,y;

    cin >> n;

    cin>> x >> y;

    vi ans(n+1,0);

    for(int i=1;i<=n;++i){

        if(!(i&1)) ans[i]=1;

    }

    if(n&1)

    ans[n]=2;

    if((x&1)==(y&1)){

        ans[y]=2;

        if(n&1){

            if(y==n-1){

                ans[n]=1;

            }

            else if(y==n-2){

                ans[n-1]=0;

                ans[n]=1;

            }

        }

    }

    

    for(int i=1;i<=n;++i){

        cout << ans[i] << " ";

    }

    cout << endl;

    }

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

#include<algorithm>

using namespace std;

#define int long long

#define pub push_back  

#define pob pop_back  

#define cin(v) for(auto &val:v) cin >> val  

#define cout(v) for(auto &val:v) cout <<val <<" ";cout << endl;

#define vi vector<int>

#define all(v) v.begin(),v.end()

#define endl "\n"

// Dont't get stuck on one approach ::

const int M=1e9+7;

int binexp(int a,int b){

  int ans=1;

  while(b){

    if(b&1){

      ans=(ans*a)%M;

    }

    a=(a*a)%M;

    b>>=1;

  }

  return ans;

}

signed main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  int t;

  cin >> t;

  while(t--){

    int n,x,y;

    cin >> n;

    cin>> x >> y;

    vi ans(n+1,0);

    for(int i=1;i<=n;++i){

        if(!(i&1)) ans[i]=1;

    }

    ans[n]=2;

    if((x&1)==(y&1)){

        ans[y]=2;

    }

    for(int i=1;i<=n;++i){

        cout << ans[i] << " ";

    }

    cout << endl;

    }

}



Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

#include<algorithm>

using namespace std;

#define int long long

#define pub push_back  

#define pob pop_back  

#define cin(v) for(auto &val:v) cin >> val  

#define cout(v) for(auto &val:v) cout <<val <<" ";cout << endl;

#define vi vector<int>

#define all(v) v.begin(),v.end()

#define endl "\n"

// Dont't get stuck on one approach ::

const int M=1e9+7;

int binexp(int a,int b){

  int ans=1;

  while(b){

    if(b&1){

      ans=(ans*a)%M;

    }

    a=(a*a)%M;

    b>>=1;

  }

  return ans;

}

signed main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  int t;

  cin >> t;

  while(t--){

    int n,x,y;

    cin >> n;

    cin>> x >> y;

    vi ans(n+1,0);

    for(int i=1;i<=n;++i){

        if(!(i&1)) ans[i]=1;

    }

    if(n&1)

    ans[n]=2;

    if((x&1)==(y&1)){

        ans[y]=2;

    }

    if(n&1){

        if(y==n-1){

            ans[n]=1;

        }

        else if(y==n-2){

            ans[n-1]=0;

            ans[n]=1;

        }

    }

    for(int i=1;i<=n;++i){

        cout << ans[i] << " ";

    }

    cout << endl;

    }

}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define fi first
#define se second
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define cntbit __builtin_popcountll
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;
const int N = 200010; 
const int inf = 1ll<<62;
const int mod = 998244353;
void chkmax(int &a,int b){
    a = max(a, b);
}
void chkmin(int &a,int b){
	a = min(a, b);
}
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}
void sub(int &a,int b){
	a -= b;
	if(a < 0) a += mod;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int qmi(int a, int b) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
vector<int> con(int x){
	
	vector<int> r;
	while(x){
		r.pb(x&1);
		x/=2;
	}
	reverse(all(r));
	return r;
}
void solve(){
	int l,r;
	cin>>l>>r;
	int base=0;
	vector<int> L=con(l);
	vector<int> R=con(r);
	if(L.size()<R.size()){
		vector<int> nl;
		int di=R.size()-L.size();
		while(di--) nl.pb(0);
		L=nl;
	}
	
	int s=0,sum=0,val=1,len=R.size();
	rep(i,0,len-1){
		val*=2;
	}
	while(s<len&&L[s]==R[s]){
		s++;
		sum+=val;
		val/=2;
	}
	int lef=len-s;
	int num=1;
	rep(i,0,lef-1) num*=2;
	if(l-sum<=num-2){
		cout<<(sum+num)<<" "<<(sum+num-1)<<" "<<(sum+num-2)<<endl;
	}else{
		cout<<(sum+num)<<" "<<(sum+num+1)<<" "<<(sum+num-1)<<endl;
	}
	
}
signed main() {
	
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout<<fixed<<setprecision(12);
    int T = 1;cin>>T;
    while (T--) {
        solve(); 
    }

}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Memory limit exceeded on test 4):
#include <iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>
#include <numeric>
#include <set>
#include <unordered_map>
using namespace std;
#define ll long long 

#define vl vector<ll>
#define vs vector<string>
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
void solve();

int main(){
    ll t;
    cin>>t;
    while(t--){solve();}
    return 0;
}

void solve(){
    string digits;
    cin>>digits;
    ll count2=0;
    ll count3=0;
    ll basesum=0;
    vl digitslist;
    for (char c:digits){
        basesum+=c-'0';
        if ((c-'0')==2){
            count2+=1;
        }
        else if ((c-'0')==3){
            count3+=1;
        }
    }
    
    if (basesum%9==0){cout<<"yes"<<endl;return;}
    vector <vl> dp(count2+1,vector<ll>(count3+1,0));
    for (ll i=0;i<=count2;i++){
        for (ll j=0;j<=count3;j++){
            if (i-1<0 && j-1<0){
                dp[i][j]=basesum%9;
                if (basesum==0){cout<<"yes"<<endl;return;}
            }
            else if (i-1<0 && j-1>=0){
                dp[i][j]=(dp[i][j-1]+6)%9;
                if (dp[i][j]==0){cout<<"yes"<<endl;return;}
            }
            else if (i-1>=0 && j-1<0){
                dp[i][j]=(dp[i-1][j]+2)%9;
                if (dp[i][j]==0){cout<<"yes"<<endl;return;}
            }
            else{
                dp[i][j] = (dp[i-1][j-1]+8)%9;
                if (dp[i][j]==0){cout<<"yes"<<endl;return;}
            }
            
        }
    }
    cout<<"no"<<endl;
    return;
}

Submission (verdict: Accepted):
#include <iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>
#include <numeric>
#include <set>
#include <unordered_map>
using namespace std;
#define ll long long 

#define vl vector<ll>
#define vs vector<string>
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
void solve();

int main(){
    ll t;
    cin>>t;
    while(t--){solve();}
    return 0;
}

void solve(){
    string digits;
    cin>>digits;
    ll count2=0;
    ll count3=0;
    ll basesum=0;
    vl digitslist;
    for (char c:digits){
        basesum+=c-'0';
        if ((c-'0')==2){
            count2+=1;
        }
        else if ((c-'0')==3){
            count3+=1;
        }
    }
    basesum=basesum%9;
    if (basesum==0){cout<<"yes"<<endl;return;}
    for (int i=0;i<=count2;i++){
        for (int j=0;j<=count3;j++){
            if ((basesum + 2*i + 6*j)%9==0){
                cout<<"yes"<<endl;return;
            }
        }
    }
    cout<<"no"<<endl;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Memory limit exceeded on test 4):
#include <iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>
#include <numeric>
#include <set>
#include <unordered_map>
using namespace std;
#define ll long long 

#define vl vector<ll>
#define vs vector<string>
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
void solve();

int main(){
    ll t;
    cin>>t;
    while(t--){solve();}
    return 0;
}

void solve(){
    string digits;
    cin>>digits;
    ll count2=0;
    ll count3=0;
    ll basesum=0;
    vl digitslist;
    for (char c:digits){
        digitslist.push_back(c-'0');
        basesum+=c-'0';
        if ((c-'0')==2){
            count2+=1;
        }
        else if ((c-'0')==3){
            count3+=1;
        }
    }
    if (basesum%9==0){cout<<"yes"<<endl;return;}
    vector <vl> dp(count2+1,vector<ll>(count3+1,0));
    for (ll i=0;i<=count2;i++){
        for (ll j=0;j<=count3;j++){
            if (i-1<0 && j-1<0){
                dp[i][j]=basesum%9;
                if (basesum==0){cout<<"yes"<<endl;return;}
            }
            else if (i-1<0 && j-1>=0){
                dp[i][j]=(dp[i][j-1]+6)%9;
                if (dp[i][j]==0){cout<<"yes"<<endl;return;}
            }
            else if (i-1>=0 && j-1<0){
                dp[i][j]=(dp[i-1][j]+2)%9;
                if (dp[i][j]==0){cout<<"yes"<<endl;return;}
            }
            else{
                dp[i][j] = (dp[i-1][j-1]+8)%9;
                if (dp[i][j]==0){cout<<"yes"<<endl;return;}
            }
            
        }
    }
    cout<<"no"<<endl;
    return;
}
Problem: 2049B - pspspsps
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#include<cctype>

 

typedef long long int ll;

typedef vector<ll> vll;

typedef vector<vector<ll>> vvll;

typedef vector<pair<ll, ll>> vpll;

typedef map<ll, ll> mll;

typedef map<char, ll> mcl;

typedef unordered_map<ll, ll> umll;

typedef unordered_map<char, ll> umcl;

typedef set<ll> sll;

typedef pair<ll, ll> pll;

typedef queue<ll> qll;

typedef deque<ll> dqll;

typedef priority_queue<ll> pqll;

 

#define Jay ios_base::sync_with_stdio(false);

#define Shree cin.tie(NULL);

#define Ram cout.tie(NULL);

#define yes cout << "YES" << "\n";

#define no cout << "NO" << "\n";

#define nope cout<<-1<<"\n";

#define ZZ cout<<0<<"\n";

#define cspace cout<<"\n";

#define endl '\n'

#define inarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];

#define outarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define sz(v) (ll)(v.size())

#define fl(i, n) for(ll i=0; i<n; i++)

#define f(i, x, n) for(ll i=x; i<n; i++)

#define rf(i, n) for(ll i=n-1; i>=0; i--)

#define fr(e, x) for(auto &e:x)

#define RR return;

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

#define pf push_front

 

const ll MOD=1e9+7;

const ll N=1e7+7;

const ll PI=3.141592653589793238462643;

 

bool isPrime(ll n){if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5; i*i<=n; i+=6) {if(n%i==0 || n%(i+2)==0) return false;} return true;}

bool isPowerOfTwo(ll n){if(n==0)return false;return (ceil(log2(n))==floor(log2(n)));}

bool isPerfectSquare(ll x){if(x>=0){ll sr=sqrt(x);return (sr*sr==x);}}

bool isInteger(double n){return floor(n)==n;}

 

ll findMEX(const set<ll>&s){ll mex=0;while(s.find(mex)!=s.end()){mex++;}return mex;}

 

void solve()

{

    ll n;

    cin>>n;

    string s;

    cin>>s;

    if(count(all(s), '.')==n) yes

    else if(s[0]=='s' || s[n-1]=='p') yes

    else no

}

 

int main()

{

    Jay Shree Ram



    int t;

    cin >> t;



    while (t--)

    {

        solve();

    }



    return 0;

}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<ll>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<ll>b;
      if(n==1){
        cout<<a[0]<<endl;
        continue;

      }
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        ans = max(ans,abs(s));
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;

        b.clear();
      }

      cout<<ans<<endl;
    }

  return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<ll>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<ll>b;
      
      int cnt = 1;
      ans = accumulate(a.begin(),a.end(),0ll);
      
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        if(cnt>1)
        ans = max(ans,abs(s));
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;
        b.clear();
        cnt++;
      }

      cout<<ans<<endl;
    }

  return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<int>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<int>b;
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        ans = max(ans,s);
        reverse(a.begin(),a.end());
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;
        b.clear();
      }

      cout<<ans<<endl;
    }

  return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<ll>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<ll>b;
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        ans = max(ans,s);
        reverse(a.begin(),a.end());
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;
        b.clear();
      }

      cout<<ans<<endl;
    }

  return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<ll>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<ll>b;
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        ans = max(ans,s);
        reverse(a.begin(),a.end());
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;
        b.clear();
      }

      cout<<ans<<endl;
    }

  return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<ll>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<ll>b;
      if(n==1){
        cout<<a[0]<<endl;
        continue;

      }
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        ans = max(ans,abs(s));
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;

        b.clear();
      }

      cout<<ans<<endl;
    }

  return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
      int n;
      cin>>n;
      vector<int>a(n);

      for(int i=0;i<n;i++) cin>>a[i];
      ll ans = INT_MIN;
      vector<int>b;
      while(a.size()>0){
        ll s = accumulate(a.begin(),a.end(),0ll);
        ans = max(ans,s);
        reverse(a.begin(),a.end());
        for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);
        a = b;
        b.clear();
      }

      cout<<ans<<endl;
    }

  return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
// 1

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

const long long MOD = 1e9+7;
const int N = 1e6 + 10;
#define MIN_IN(A) *(std::min_element(A.begin(), A.end()))
#define MAX_IN(A) *(std::max_element(A.begin(), A.end()))
#define MAX_AT(A) (std::max_element(A.begin(), A.end()) - A.begin())
#define MIN_AT(A) (std::min_element(A.begin(), A.end()) - A.begin())
#define pb push_back
#define SORT(A) std::sort(A.begin(), A.end())
#define RSORT(A) std::sort(A.rbegin(), A.rend())
#define REVERSE(A) std::reverse(A.begin(), A.end())
#define VECIN(A,n) for(int i = 0; i < n; i++) { cin >> A[i]; }
#define VECIN1(A,n) for(int i = 1; i <=n; i++) { cin >> A[i]; }
#define VECOUT(A) for(int i = 0; i < A.size(); i++) { cout << A[i] << " "; } cout << endl;
#define COUT(A) cout << A << endl;
#define ll long long
#define ull unsigned long long
#define D double
#define UI unsigned int
#define Y1 cout<<"yes"<<endl
#define N1 cout<<"no"<<endl


ll power(ll x, ll y) {
    ll res = 1;
    x = x % MOD; 
    while (y > 0) {  
        if (y & 1) 
            res = (res * x) % MOD;  
        y = y >> 1;
        x = (x * x) % MOD;   
    } 
    return res; 
}

ll __gcd(ll a, ll b) { 
    if (b == 0) 
    { 
        return a; 
    } 
    return __gcd(b, a % b); 
}

ll __LCM(ll a, ll b){
    return (a * b) / __gcd(a, b);
}

ll xorn(int n){
    if(n % 4 == 0) return n;
    if(n % 4 == 3) return 0;
    if(n % 4 == 1) return 1;
    return n ^ 1;
}

bool ispalindrome(string s){
    int si = s.size();
    for(int i = 0; i < si / 2; i++){
        if(s[i] != s[si - 1 - i]) return false;
    }
    return true;
}

void solve() 
{
    ll n;
    cin>>n;

    ll no2=0,no3=0,sum=0;

    while(n!=0)
    {
        int a=n%10;
        if(a==2) no2++;
        else if(a==3) no3++;
        n/=10;
        sum+=a;
    }



    for(int i=0;i<=no2;i++)
    {
        for(int j=0;j<=no3;j++)
        {
            
            if((sum+2*i+6*j)%9==0) 
            {
                COUT("yes");
                return;
            }
        }
    }
    COUT("NO");

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) 
    {
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void dfs(int node, vector<set<int>>& adj, vector<int>& vis) {
    vis[node] = 1;
    
    for (auto it : adj[node]) {
        if (!vis[it]) {
            dfs(it, adj, vis);
        }
    }
}

void solve() {
    int n;
    cin >> n;
    
    vector<set<int>> adj(n + 1);
    vector<int> vis(n + 1, 0);
    
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        
        adj[u].insert(v);
        adj[v].insert(u);
    }
    
    // for(int i = 1; i<=n; i++){
    //     cout << i << " :- ";
    //     for(auto it : adj[i]){
    //         cout << it << " ";
    //     }
    //     cout << endl;
    // }
    
    int largest = -1;
    int ind = -1;
    for (int i = 1; i <= n; i++) {
        if(vis[i] == 1) continue;
        int size = adj[i].size();
        if (size > largest) {
            largest = size;
            ind = i;
        }
    }
    
    //cout << ind << endl;
    
    for (auto it : adj[ind]) {
        adj[it].erase(ind);
    }
    adj[ind].clear();
    vis[ind] = 1;
    
    // cout << " after 1st clear " << endl;
    // for(int i = 1; i<=n; i++){
    //     if(vis[i] == 1) continue;
    //     cout << i << " :- ";
    //     for(auto it : adj[i]){
    //         cout << it << " ";
    //     }
    //     cout << endl;
    // }
    
    
    largest = -1;
    ind = -1;
    for (int i = 1; i <= n; i++) {
        if(vis[i] == 1) continue;
        int size = adj[i].size();
        if (size > largest) {
            largest = size;
            ind = i;
        }
    }
    
    //cout << ind << endl;
    
    for (auto it : adj[ind]) {
        adj[it].erase(ind);
    }
    adj[ind].clear();
    vis[ind] = 1;
    
    // cout << " after 2nd clear " << endl;
    // for(int i = 1; i<=n; i++){
    //     if(vis[i] == 1) continue;
    //     cout << i << " :- ";
    //     for(auto it : adj[i]){
    //         cout << it << " ";
    //     }
    //     cout << endl;
    // }
    
    int comp = 0;
    // for(auto it : vis){
    //     cout << it << " ";
    // }
    // cout  << endl;
    
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            comp++;
            dfs(i, adj, vis);
        }
        
        // cout << "i :- " << i << endl;
        // for(auto it : vis){
        //     cout << it << " ";
        // }
        // cout << endl;
        
    }
    
    cout << comp << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    cin >> t;
    
    while (t--) {
        solve();
    }
    return 0;
}