ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3 + 9;
mt19937 rnd(time(0));
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 1e9 + 7;
const int P = rnd() % mod;
int c[N];
vector<pii> v;
void solve() {
    int n; cin >> n;
    for(int i = 1;i <= n;i++) cin >> c[i];
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(c[i] > c[j]) v.push_back({c[j],c[i]});
            else {
                v.push_back({c[j],c[i]});
                v.push_back({c[i],c[j]});
            }
        }
    }
    cout << v.size() << "\n";
    for(auto [x,y] : v) {
        cout << x << " " << y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3 + 9;
mt19937 rnd(time(0));
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 1e9 + 7;
const int P = rnd() % mod;
int c[N];
vector<pii> v;
void solve() {
    int n; cin >> n;
    for(int i = 1;i <= n;i++) cin >> c[i];
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(c[i] > c[j]) v.push_back({c[i],c[j]});
            else {
                v.push_back({c[j],c[i]});
                v.push_back({c[i],c[j]});
            }
        }
    }
    cout << v.size() << "\n";
    for(auto [x,y] : v) {
        cout << x << " " << y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3 + 9;
mt19937 rnd(time(0));
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 1e9 + 7;
const int P = rnd() % mod;
int c[N];
void solve() {
    int n; cin >> n;
    for(int i = 1;i <= n;i++) cin >> c[i];
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(c[i] > c[j]) {
                cout << c[j] << " " << c[i] << "\n";
                ans++;
            }
            else {
                cout << c[j] << " " << c[i] << "\n";
                cout << c[i] << " " << c[j] << "\n";
                ans += 2;
            }
        }
    }
    cout << ans << "\n";
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3 + 9;
mt19937 rnd(time(0));
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 1e9 + 7;
const int P = rnd() % mod;
int c[N];
vector<pii> v;
void solve() {
    int n; cin >> n;
    for(int i = 1;i <= n;i++) cin >> c[i];
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(c[i] > c[j]) v.push_back({c[j],c[i]});
            else {
                v.push_back({c[j],c[i]});
                v.push_back({c[i],c[j]});
            }
        }
    }
    cout << v.size() << "\n";
    for(auto [x,y] : v) {
        cout << x << " " << y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3 + 9;
mt19937 rnd(time(0));
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 1e9 + 7;
const int P = rnd() % mod;
int c[N];
void solve() {
    int n; cin >> n;
    for(int i = 1;i <= n;i++) cin >> c[i];
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(c[i] > c[j]) {
                cout << c[j] << " " << c[i] << "\n";
                ans++;
            }
            else {
                cout << c[j] << " " << c[i] << "\n";
                cout << c[i] << " " << c[j] << "\n";
                ans += 2;
            }
        }
    }
    cout << ans << "\n";
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;



#define pi (3.141592653589)

#define mod 1000000007

#define pb push_back

#define is insert

#define mp make_pair

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define rfr(n) for(int i=n-1;i>=0;i--)

#define rep1(i,a,b) for(long long i=a;i<=b;i++)

#define fr(n) for(long long i=0;i<n;i++)

#define nesfr(x,y) for(long long i=0;i<x;i++)for(long long j=0;j<y;j++)

#define rep(i,a,b) for(long long i=a;i<b;i++)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long ll;

typedef long double ld;

typedef vector<ll> vi;

#define nl cout << "\n"

void solve(); 



int main() {

    fast;

    ll t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}



const int MAX_BIT = 30;

const int MOD = 998244353;

int add(int x, int y) {

  x += y;

  if (x >= MOD) x -= MOD;

  return x;

}



void solve() {

int n, l, r; cin >> n >> l >> r;

std::vector<int> v(n);

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

{

    cin >> v[i];

}

sort( v.begin(), v.end());

int sum =0;

for (int i = 0; i <= r-l; ++i)

{

    sum+=v[i];

}

cout << sum << endl;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#define pi (3.141592653589)
#define mod 1000000007
#define pb push_back
#define is insert
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfr(n) for(int i=n-1;i>=0;i--)
#define rep1(i,a,b) for(long long i=a;i<=b;i++)
#define fr(n) for(long long i=0;i<n;i++)
#define nesfr(x,y) for(long long i=0;i<x;i++)for(long long j=0;j<y;j++)
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define nl cout << "\n"
void solve(); 

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

const int MAX_BIT = 30;
const int MOD = 998244353;
int add(int x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
  return x;
}

void solve() {
ll n, l, r; cin >> n >> l >> r;
std::vector<ll> v(n);
for (ll i = 0; i < n; ++i)
{
    cin >> v[i];
}
sort( v.begin(), v.end());
ll sum =0;
for (ll i = 0; i <= r-l; ++i)
{
    sum+=v[i];
}
cout << sum << endl;
}


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

using namespace std;



#define pi (3.141592653589)

#define mod 1000000007

#define pb push_back

#define is insert

#define mp make_pair

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define rfr(n) for(int i=n-1;i>=0;i--)

#define rep1(i,a,b) for(long long i=a;i<=b;i++)

#define fr(n) for(long long i=0;i<n;i++)

#define nesfr(x,y) for(long long i=0;i<x;i++)for(long long j=0;j<y;j++)

#define rep(i,a,b) for(long long i=a;i<b;i++)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long ll;

typedef long double ld;

typedef vector<ll> vi;

#define nl cout << "\n"

void solve(); 



int main() {

    fast;

    ll t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}



const int MAX_BIT = 30;

const int MOD = 998244353;

int add(int x, int y) {

  x += y;

  if (x >= MOD) x -= MOD;

  return x;

}



void solve() {

// ll n, l, r; cin >> n >> l >> r;

// std::vector<ll> v(n);

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

// {

//     cin >> v[i];

// }

// // sort( v.begin(), v.end());

// ll sum =0;

// // for (ll i = 0; i <= r-l; ++i)

// // {

// //     sum+=v[i];

// // }

// int count = r-l+1;

// while(!v.empty()){

    

// }



int l,r;

long long int a[100000],b[100000],s=0,t=0,n;

cin>>n>>l>>r;

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

{cin>>a[i];

b[i]=a[i];}

sort(a,a+r);

for(int i=0;i<(r+1-l);i++)

s+=a[i];

sort(b+l-1,b+n);

for(int i=l-1;i<(r);i++)

t+=b[i];

cout<<min(s,t)<<endl;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;



#define pi (3.141592653589)

#define mod 1000000007

#define pb push_back

#define is insert

#define mp make_pair

#define ff first

#define ss second

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

#define min3(a, b, c) min(c, min(a, b))

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

#define rfr(n) for(int i=n-1;i>=0;i--)

#define rep1(i,a,b) for(long long i=a;i<=b;i++)

#define fr(n) for(long long i=0;i<n;i++)

#define nesfr(x,y) for(long long i=0;i<x;i++)for(long long j=0;j<y;j++)

#define rep(i,a,b) for(long long i=a;i<b;i++)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long ll;

typedef long double ld;

typedef vector<ll> vi;

#define nl cout << "\n"

void solve(); 



int main() {

    fast;

    ll t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}



const int MAX_BIT = 30;

const int MOD = 998244353;

int add(int x, int y) {

  x += y;

  if (x >= MOD) x -= MOD;

  return x;

}



void solve() {

int n, l, r; cin >> n >> l >> r;

std::vector<int> v(n);

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

{

    cin >> v[i];

}

sort( v.begin(), v.end());

int sum =0;

for (int i = 0; i <= r-l; ++i)

{

    sum+=v[i];

}

cout << sum << endl;

}



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

#define pi (3.141592653589)
#define mod 1000000007
#define pb push_back
#define is insert
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfr(n) for(int i=n-1;i>=0;i--)
#define rep1(i,a,b) for(long long i=a;i<=b;i++)
#define fr(n) for(long long i=0;i<n;i++)
#define nesfr(x,y) for(long long i=0;i<x;i++)for(long long j=0;j<y;j++)
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define nl cout << "\n"
void solve(); 

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

const int MAX_BIT = 30;
const int MOD = 998244353;
int add(int x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
  return x;
}

void solve() {
ll n, l, r; cin >> n >> l >> r;
std::vector<ll> v(n);
for (ll i = 0; i < n; ++i)
{
    cin >> v[i];
}
sort( v.begin(), v.end());
ll sum =0;
for (ll i = 0; i <= r-l; ++i)
{
    sum+=v[i];
}
cout << sum << endl;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    while (bit(r, i) == bit(l, i))
        i--;
    int a = 1 << i;
    if (a - 2 >= l)
        cout << a << " " << a - 1 << " " << a - 2 << "\n";
    else
        cout << a << " " << a - 1 << " " << a + 1 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}


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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    int X = 0;
    while (bit(r, i) == bit(l, i)) {
        if (bit(r, i))
            X += 1 << i;
        i--;
    }
    int a = 1 << i;
    if (X + a - 2 >= l)
        cout << X + a << " " << X + a - 1 << " " << X + a - 2 << "\n";
    else
        cout << X + a << " " << X + a - 1 << " " << X + a + 1 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    while (bit(r, i) == bit(l, i))
        i--;
    int a = 1 << i;
    cout << a << " " << a - 1 << " " << a - 1 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}


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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    while (bit(r, i) == bit(l, i))
        i--;
    int a = 1 << i;
    cout << a << " " << a - 1 << " " << a - 2 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    while (bit(r, i) == bit(l, i))
        i--;
    int a = 1 << i;
    cout << a << " " << a - 1 << " " << a - 1 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    while (bit(r, i) == bit(l, i))
        i--;
    int a = 1 << i;
    cout << a << " " << a - 1 << " " << a - 2 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}


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

// #pragma GCC optimize("O3")

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Size(a) (int)a.size()
#define ll long long
#define ld long double

// #define int long long

using namespace std;

bool bit(int mask, int i) {
    return (mask >> i) & 1;
}

void solve() {
    int l, r;
    cin >> l >> r;
    int i = 30;
    while (bit(r, i) == bit(l, i))
        i--;
    int a = 1 << i;
    if (a - 2 >= l)
        cout << a << " " << a - 1 << " " << a - 2 << "\n";
    else
        cout << a << " " << a - 1 << " " << a + 1 << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #ifdef dimss
        freopen("test.txt", "r", stdin);
    #endif

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        #ifdef dimss
            cerr << "--------\n";
        #endif
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define loop(i, x, y) for (int i = x; i < y; i++)
#define rloop(i, x, y) for (int i = x; i >= y; i--)
#define all(arr) arr.begin(),arr.end()
#define rt return
#define mpp map<int,int>
#define ff first
#define ss second
#define pb push_back
#define sortv(arr) sort(arr.begin(), arr.end())
#define rsortv(arr) sort(arr.begin(), arr.end(), greater<int>())
#define pii pair<int, int>
#define br cout << endl
#define dbg(a) cout<<a<<endl
#define ct continue
#define disp(a)                        \
  {                                    \
    for (int i = 0; i < a.size(); i++) \
      cout << a[i] << " ";             \
    cout << endl;                      \
  }
#define inp(a)                         \
  {                                    \
    for (int i = 0; i < a.size(); i++) \
      { cin >> a[i]; }                 \
  }
void Dinesh(){
  string s;
  cin>>s;
  string temp;
  int x=min((int)s.size(),10ll);
  loop(i,0,x){
    temp+=s[i];
  }
  // cout<<temp;
  string ans;
  loop(i,0,(int)s.size()){
     char c=temp[0];
     int pos=0;
    loop(i,1,temp.size()){
      if((temp[i]-'0')-i>(c-'0')){
        c=temp[i]-i;
        pos=i;
      }
    }
  ans+=c;
  string temp1 = (pos > 0 ? temp.substr(0, pos) : "") + temp.substr(pos + 1);
  if(i+11<(int)s.size())temp1+=s[i+11];
  temp=temp1;
  }
  cout<<ans;br;


}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin >> t;
    while (t--) {
        Dinesh();
    }

    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
#define vi vector<int>
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define loop(i, x, y) for (int i = x; i < y; i++)
#define rloop(i, x, y) for (int i = x; i >= y; i--)
#define all(arr) arr.begin(), arr.end()
#define rt return
#define mpp map<int, int>
#define ff first
#define ss second
#define pb push_back
#define sortv(arr) sort(arr.begin(), arr.end())
#define rsortv(arr) sort(arr.begin(), arr.end(), greater<int>())
#define pii pair<int, int>
#define br cout << endl
#define dbg(a) cout << a << endl
#define ct continue
#define disp(a)                        \
  {                                    \
    for (int i = 0; i < a.size(); i++) \
      cout << a[i] << " ";             \
    cout << endl;                      \
  }
#define inp(a)                         \
  {                                    \
    for (int i = 0; i < a.size(); i++) \
      { cin >> a[i]; }                 \
  }
const int mod = 998244353;
long long mod_exp(long long base, long long exp, long long mod) {
    long long result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) { // If exp is odd
            result = (result * base) % mod;
        }
        base = (base * base) % mod; // Square the base
        exp /= 2; // Halve the exponent
    }
    return result;
}
 
long long mod_inverse(long long a, long long mod) {
    return mod_exp(a, mod - 2, mod); // Using modular exponentiation
}
void dfs(int i,vi& vis,vi adj[]){
   vis[i]=1;
   for(auto it :adj[i]){
    if(!vis[it])dfs(it,vis,adj);
   }
}
void Dinesh() {
  int n;
  cin>>n;
  vi deg(n+1);
  vector<pii>edges;
  loop(i,0,n-1){
    int u,v;
    cin>>u>>v;
    deg[u]++;
    deg[v]++;
    edges.pb({u,v});
  }
  int mx1=max_element(deg.begin(),deg.end())-deg.begin(),mx2=0,val2=0;
  loop(i,1,n+1){
    if(i!=mx1 && deg[i]>val2){
      val2=deg[i];
      mx2=i;
    }
  }
  vi adj[n+1];
  for(auto it:edges){
    int u=it.ff,v=it.ss;
    if(u==mx1 || u==mx2 || v==mx1 || v==mx2){
      continue;
    }
    adj[u].pb(v);
    adj[v].pb(u);
  }
  vi vis(n+1);
  int ans=0;
  loop(i,1,n+1){
    if(i!=mx1 && i!=mx2 && !vis[i]){
      ans++;
      dfs(i,vis,adj);
    }
  }
  dbg(ans);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        Dinesh();
    }
    return 0;
}