ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int t;
int l, r;

void solve() {
    cin >> l >> r;
    int x = r;

    int k = 0;
    for (int i = 0; i <= 30; i++) {
        if (x & (1 << i)) {
            k = i;
        }
    }
    int y = 0;
    for (int i = 0; i <= k; i++) {
        if ((x & (1 << i)) == 0) {
            y |= (1 << i);
        }
    }

    if (y < l)
        y |= l;

    if (y + 1 >= r) {
        cout << x << " " << y << " " << y - 1 << "\n";
    } else {
        cout << x << " " << y << " " << y + 1 << "\n";
    }
}

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


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int t;
int l, r;

void solve() {
    cin >> l >> r;
    int x = r;

    int k = 0;
    for (int i = 0; i <= 30; i++) {
        if (x & (1 << i)) {
            k = i;
        }
    }
    int y = 0;
    for (int i = 0; i <= k; i++) {
        if ((x & (1 << i)) == 0) {
            y |= (1 << i);
        }
    }

    // if (y < l)
    y |= l;

    if (y + 1 >= r) {
        cout << x << " " << y << " " << y - 1 << "\n";
    } else {
        cout << x << " " << y << " " << y + 1 << "\n";
    }
}

int main() {
    cin >> t;
    while (t--) solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + 2){

				k++; 

				if(a.count(b[b.size() - 1]) > 0){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					if(a.count(x1) > 0){

						a.erase(a.find(x1));

					}

					else{

						b.push_back(x1);

					}

					if(a.count(x2) > 0){

						a.erase(a.find(x2));

					}

					else{

						b.push_back(x2);

					}

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}

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

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + 2){

				k++; 

				if(a.find(b[b.size() - 1]) != a.end()){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					if(a.find(x1) != a.end()){

						a.erase(a.find(x1));

					}

					else{

						b.push_back(x1);

					}

					if(a.find(x2) != a.end()){

						a.erase(a.find(x2));

					}

					else{

						b.push_back(x2);

					}

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + m){

				k++; 

				if(a.count(b[b.size() - 1]) > 0){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					if(a.count(x1) > 0){

						a.erase(a.find(x1));

					}

					else{

						b.push_back(x1);

					}

					if(a.count(x2) > 0){

						a.erase(a.find(x2));

					}

					else{

						b.push_back(x2);

					}

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}

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

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + m){

				k++; 

				if(a.count(b[b.size() - 1]) > 0){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					b.push_back(x1);

					b.push_back(x2);

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + m){

				k++; 

				if(a.count(b[b.size() - 1]) > 0){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					if(a.count(x1) > 0){

						a.erase(a.find(x1));

					}

					else{

						b.push_back(x1);

					}

					if(a.count(x2) > 0){

						a.erase(a.find(x2));

					}

					else{

						b.push_back(x2);

					}

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

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

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + m){

				k++; 

				if(a.count(b[b.size() - 1]) > 0){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					b.push_back(x1);

					b.push_back(x2);

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

}

Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>

#define ll long long int

#define pb push_back



using namespace std;



const int MAXN = 2e5 + 10;



int main(){

		

	ll t;

	scanf("%lld", &t);



	while(t--){

		ll n, m, x;

		scanf("%lld %lld", &n, &m);



		multiset<ll> a;

		vector<ll> b;

		ll suma_a = 0;

		ll suma_b = 0;



		for(ll i = 0; i < n; i++){

			scanf("%lld", &x);

			suma_a += x;

			a.insert(x);

		}



		for(ll i = 0; i < m; i++){

			scanf("%lld", &x);

			suma_b += x;

			b.pb(x);

		}



		if(suma_a != suma_b){

			printf("No\n");

		}

		else{

			ll k = 0;

			while(b.size() > 0 && k <= n + 2){

				k++; 

				if(a.count(b[b.size() - 1]) > 0){

					a.erase(a.find(b[b.size() - 1]));

					b.pop_back();

				}

				else{

					ll x1 = b[b.size() - 1]/2;

					ll x2 = b[b.size() - 1]/2;

					if(b[b.size() - 1] % 2 == 1){

						x2++;

					}

					b.pop_back();

					if(a.count(x1) > 0){

						a.erase(a.find(x1));

					}

					else{

						b.push_back(x1);

					}

					if(a.count(x2) > 0){

						a.erase(a.find(x2));

					}

					else{

						b.push_back(x2);

					}

				}

			}

			if(b.size() == 0){

				printf("Yes\n");

			}

			else{

				printf("No\n");

			}

		}

	}	

	

	return 0;

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


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

using namespace std;

int main() {

    int i,t;

    cin >> t;

    while(t--){

        int n;

        int sum =0;

        int target =0;

        cin >> n;

        int arr[n];

        for(i=0;i<n;i++){

            cin >> arr[i];

            sum+=arr[i];

        }

        if(sum%n==0){

            target=sum/n;

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

                arr[i+1]+=(arr[i-1]-target);

                arr[i-1]=target;

            }

            /*for(i=0;i<n;i++){

                cout << arr[i] << " ";

            }

            cout << endl;*/

            if(arr[n-1]==target&&arr[n-2]==target){

                cout << "YES" << endl;

            }

            else {

                cout << "NO" << endl;

            }

        }

        else{

            cout << "NO" << endl;

        }

    }

    cin >> t;

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

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

using namespace std;

int main() {

    int i,t;

    cin >> t;

    while(t--){

        int n;

        long int sum =0;

        int target =0;

        cin >> n;

        int arr[n];

        for(i=0;i<n;i++){

            cin >> arr[i];

            sum+=arr[i];

        }

        if(sum%n==0){

            target=sum/n;

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

                arr[i+1]+=(arr[i-1]-target);

                arr[i-1]=target;

            }

            /*for(i=0;i<n;i++){

                cout << arr[i] << " ";

            }

            cout << endl;*/

            if(arr[n-1]==target&&arr[n-2]==target){

                cout << "YES" << endl;

            }

            else {

                cout << "NO" << endl;

            }

        }

        else{

            cout << "NO" << endl;

        }

    }

    cin >> t;

}

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

using namespace std;

int main() {

    int i,t;

    cin >> t;

    while(t--){

        int n;

        long long int sum =0;

        int target =0;

        cin >> n;

        int arr[n];

        for(i=0;i<n;i++){

            cin >> arr[i];

            sum+=arr[i];

        }

        if(sum%n==0){

            target=sum/n;

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

                arr[i+1]+=(arr[i-1]-target);

                arr[i-1]=target;

            }

            /*for(i=0;i<n;i++){

                cout << arr[i] << " ";

            }

            cout << endl;*/

            if(arr[n-1]==target&&arr[n-2]==target){

                cout << "YES" << endl;

            }

            else {

                cout << "NO" << endl;

            }

        }

        else{

            cout << "NO" << endl;

        }

    }

    cin >> t;

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

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

using namespace std;

int main() {

    int i,t;

    cin >> t;

    while(t--){

        int n;

        int sum =0;

        int target =0;

        cin >> n;

        int arr[n];

        for(i=0;i<n;i++){

            cin >> arr[i];

            sum+=arr[i];

        }

        if(sum%n==0){

            target=sum/n;

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

                arr[i+1]+=(arr[i-1]-target);

                arr[i-1]=target;

            }

            /*for(i=0;i<n;i++){

                cout << arr[i] << " ";

            }

            cout << endl;*/

            if(arr[n-1]==target&&arr[n-2]==target){

                cout << "YES" << endl;

            }

            else {

                cout << "NO" << endl;

            }

        }

        else{

            cout << "NO" << endl;

        }

    }

    cin >> t;

}

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

using namespace std;

int main() {

    int i,t;

    cin >> t;

    while(t--){

        int n;

        long int sum =0;

        int target =0;

        cin >> n;

        int arr[n];

        for(i=0;i<n;i++){

            cin >> arr[i];

            sum+=arr[i];

        }

        if(sum%n==0){

            target=sum/n;

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

                arr[i+1]+=(arr[i-1]-target);

                arr[i-1]=target;

            }

            /*for(i=0;i<n;i++){

                cout << arr[i] << " ";

            }

            cout << endl;*/

            if(arr[n-1]==target&&arr[n-2]==target){

                cout << "YES" << endl;

            }

            else {

                cout << "NO" << endl;

            }

        }

        else{

            cout << "NO" << endl;

        }

    }

    cin >> t;

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

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

		for(i=0; i<n; i++){

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

				if(l[i+2]<0){

					flag = false;

					break;

				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}

Submission (verdict: Accepted):
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

		for(i=0; i<n; i++){

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

//				if(l[i+2]<0){

//					flag = false;

//					break;

//				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

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


Submission (verdict: Wrong answer on test 3):
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	int ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%d", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%d", &n);

		for(i=0; i<n; i++){

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

				if(l[i+2]<0){

					flag = false;

					break;

				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

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

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	int ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%d", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%d", &n);

		for(i=0; i<n; i++){

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

				if(l[i+2]<0){

					flag = false;

					break;

				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}

Submission (verdict: Wrong answer on test 3):
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

		for(i=0; i<n; i++){

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

				if(l[i+2]<0){

					flag = false;

					break;

				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
class list
{
public:
    int val;
    list* next=nullptr;
};

int main() {
    int n = 0;
    cin >> n;
    vector<int> de(n);
    vector<int> pl(n+1);
    list* head=new list;
    
    head->next = new list;
    list* now = head->next;
    now->val = 1;
    vector<pair<int,int>> im;
    for (int i = 0; i < n;  ++i)
    {
        cin >> de[i];
    }
    for (int i = 0; i < n; ++i)
    {
        pl[de[i]] = i ;
    }

    for (int i = 2; i <= n; ++i)
    {
        int first=0;
        list* now = head->next;
        while (now != nullptr)
        {
            stack<int> aa;
                if (pl[now->val] > pl[i])
                {
                    {
                    pair<int, int> ppp(i, now->val);
                   
                    im.push_back(ppp);
                    }
                    if (now->next == nullptr)
                    {
                        now->next = new list;
                        now->next->val = i;
                        break;
                    }
                }
            else
            {
                pair<int, int> ppp(i, now->val);
                aa.push(now->val);
                im.push_back(ppp);
                if (first == 0)
                {
                    list* nxt = new list;
                    nxt->val = now->val;
                    nxt->next = now->next;
                    now->val = i;
                    now->next = nxt;
                    first = 1;
                }
                now = now->next;
                while (now->next != nullptr)
                {
                    aa.push(now->val);
                    pair<int, int> ppp(i, now->val);
                    im.push_back(ppp);
                    now = now->next;
                }
                while (!aa.empty()) 
                {
                    pair<int, int> ppp(aa.top(), i); im.push_back(ppp);
                    aa.pop();
                }
            }
                if (now != nullptr)
                { 
                    {
                        now = now->next;
                    }
                }
        }
    }
    cout << im.size() << endl;
    for (auto a : im)
    {
        cout << a.first << " " << a.second << endl;
    }
    //cout << n * (n - 1);
    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 IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define in_ freopen("input.txt", "r", stdin);
#define all(a) a.begin(), a.end()
#define cout2(a) for(int i = 0; i < a.size(); ++ i) cout << a[i] << " "; cout << "\n";
#define cout1(a, s, e) for(int i = s; i < e; ++ i) cout << a[i] << " "; cout << "\n";
#define debug1(x) cout << x << "!!!\n";
#define debug2(x) cout << x << "###\n";

typedef long long ll;
const int N = 200005;
typedef pair<int,int> PII;
 
#define x1 first
#define y1 second

void deal() {
	
	int n;
	cin >> n;
	
	vector<int> deg(n);
	vector<PII> e(n);
	
	for(int i = 0; i < n - 1; ++ i) {
		int u, v;
		cin >> u >> v;
		
		u --, v --;
	    deg[u] ++, deg[v] ++;
	    
	    e.push_back({u, v});
	}
	
	int ans = 0;
//	for(auto it : e) {
//		ans = max(ans, it.x1 + it.y1 - 2);
//	}
//	
	int vmax = max_element(deg.begin(), deg.end()) - deg.begin();
	
	vector<int> ok(n);
	ok[vmax] = 1;
	
	for(auto it : e) {
		if(it.x1 == vmax) ok[it.y1] = 1;
		if(it.y1 == vmax) ok[it.x1] = 1;
	}
	
	for(int i = 0; i < n; ++ i) {
		if(i == vmax) continue;
		if(ok[i]) ans = max(ans, deg[vmax] + deg[i] - 2);
		else ans = max(ans, deg[vmax] + deg[i] - 1);
	}

    cout << ans << "\n";
   	
} 

int main() {
	
	#ifndef ONLINE_JUDGE
	in_;
//	freopen("out.txt", "w", stdout); 
	#endif
	
	IOS;
	
	int t;
	cin >> t;
	while(t--)
	 deal();

	return 0;
}  

/*
       /\_/\
      (= ._.)
       />  \>  !!!!!!     
       author :: fly
	    
*/