ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        set<pair<ll, ll>> adj;
        vector<ll> deg(n);
        for(ll i = 0; i < n - 1; i++) {
            ll u, v;
            cin >> u >> v;
            u--;
            v--;
            adj.insert({u, v});
            adj.insert({v, u});
            deg[u]++;
            deg[v]++;
        }
        vector<pair<ll, ll>> e;
        for(ll i = 0; i < n; i++) {
            e.push_back({deg[i], i});
        }
        sort(e.rbegin(), e.rend());
        ll ans = 0;
        for(ll i = 0; i < n; i++) {
            for(ll j = i + 1; j < n; j++) {
                ll u = e[i].second;
                ll v = e[j].second;
                if(adj.count({u, v})) {
                    continue;
                }
                ans = max(ans, deg[u] + deg[v] - 1);
            }
        }
        for(pair p: adj) {
            ans = max(ans, deg[p.first] + deg[p.second] - 2);
        }
        cout << ans << '\n';
    }
    return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        vector<set<ll>> adj(n);
        vector<ll> deg(n);
        for(ll i = 0; i < n - 1; i++) {
            ll u, v;
            cin >> u >> v;
            u--;
            v--;
            adj[u].insert(v);
            adj[v].insert(u);
            deg[u]++;
            deg[v]++;
        }
        vector<pair<ll, ll>> e;
        for(ll i = 0; i < n; i++) {
            e.push_back({deg[i], i});
        }
        sort(e.rbegin(), e.rend());
        ll ans = 0;
        for(ll i = 0; i < n; i++) {
            for(ll j = i + 1; j < n; j++) {
                ll u = e[i].second;
                ll v = e[j].second;
                if(adj[u].count(v)) {
                    continue;
                }
                ans = max(ans, deg[u] + deg[v] - 1);
                break;
            }
        }
        for(ll i = 0; i < n; i++) {
            for(ll j: adj[i]) {
                ans = max(ans, deg[i] + deg[j] - 2);
            }
        }
        cout << ans << '\n';
    }
    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 ll long long

ll dfs(ll x, vector<set<ll>> &adj, vector<ll> &vis) {
    vis[x]++;
    ll ans = 0;
    for(ll i: adj[x]) {
        if(adj[i].size() == 0 or vis[i]) {
            continue;
        } 
        ans = dfs(i, adj, vis);
    }
    return 1 + ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        vector<set<ll>> adj(n);
        for(ll i = 0; i < n - 1; i++) {
            ll u, v;
            cin >> u >> v;
            u--;
            v--;
            adj[u].insert(v);
            adj[v].insert(u);
        }
        if(n == 2) {
            cout << "0\n";
            continue;
        }
        ll mn = adj[0].size();
        ll mnV = 0;
        for(ll i = 1; i < n; i++) {
            if(mn > adj[i].size()) {
                mn = adj[i].size();
                mnV = i;
            }
        }
        for(ll i: adj[mnV]) {
            adj[i].erase(mnV);
        }
        adj[mnV].clear();
        mn = n;
        mnV = -1;

        for(ll i = 0; i < n; i++) {
            if(adj[i].size() == 0) {
                continue;
            }
            if(mn > adj[i].size()) {
                mn = adj[i].size();
                mnV = i;
            }
        }
        for(ll i: adj[mnV]) {
            adj[i].erase(mnV);
        }
        adj[mnV].clear();

        vector<ll> vis(n);
        ll ans = 0;
        for(ll i = 0; i < n; i++) {
            if(adj[i].size() == 0 or vis[i]) {
                continue;
            }
            ans = max(ans, dfs(i, adj, vis));
        }
        cout << ans << '\n';
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        vector<set<ll>> adj(n);
        vector<ll> deg(n);
        for(ll i = 0; i < n - 1; i++) {
            ll u, v;
            cin >> u >> v;
            u--;
            v--;
            adj[u].insert(v);
            adj[v].insert(u);
            deg[u]++;
            deg[v]++;
        }
        vector<pair<ll, ll>> e;
        for(ll i = 0; i < n; i++) {
            e.push_back({deg[i], i});
        }
        sort(e.rbegin(), e.rend());
        ll ans = 0;
        for(ll i = 0; i < n; i++) {
            for(ll j = i + 1; j < n; j++) {
                ll u = e[i].second;
                ll v = e[j].second;
                if(adj[u].count(v)) {
                    continue;
                }
                ans = max(ans, deg[u] + deg[v] - 1);
            }
        }
        for(ll i = 0; i < n; i++) {
            for(ll j: adj[i]) {
                ans = max(ans, deg[i] + deg[j] - 2);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        set<pair<ll, ll>> adj;
        vector<ll> deg(n);
        for(ll i = 0; i < n - 1; i++) {
            ll u, v;
            cin >> u >> v;
            u--;
            v--;
            adj.insert({u, v});
            adj.insert({v, u});
            deg[u]++;
            deg[v]++;
        }
        vector<pair<ll, ll>> e;
        for(ll i = 0; i < n; i++) {
            e.push_back({deg[i], i});
        }
        sort(e.rbegin(), e.rend());
        ll ans = 0;
        for(ll i = 0; i < n; i++) {
            for(ll j = i + 1; j < n; j++) {
                ll u = e[i].second;
                ll v = e[j].second;
                if(adj.count({u, v})) {
                    continue;
                }
                ans = max(ans, deg[u] + deg[v] - 1);
            }
        }
        for(pair p: adj) {
            ans = max(ans, deg[p.first] + deg[p.second] - 2);
        }
        cout << ans << '\n';
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < i;j++){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = i + 1;j <= n;j++){
            if(arr[j] > arr[i]) ans.push_back({arr[i], arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < i;j++){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        vector<int> temp;
        for(int j = i + 1;j <= n;j++){
            if(arr[j] > arr[i]) temp.push_back(arr[j]);
             
        }
        sort(temp.begin(), temp.end());
        for(auto x : temp) ans.push_back({arr[i], x});
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < i;j++){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = n;j > i;j--){
            if(arr[j] > arr[i]) ans.push_back({arr[i], arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < i;j++){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = i + 1;j <= n;j++){
            if(arr[j] > arr[i]) ans.push_back({arr[i], arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = i - 1;j > 0;j--){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = n;j > i;j--){
            if(arr[j] > arr[i]) ans.push_back({arr[i], arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < i;j++){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = n;j > i;j--){
            if(arr[j] > arr[i]) ans.push_back({arr[i], arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<vector<bool>> used(n + 1, vector<bool>(n + 1, false));
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < n;j++){
            if(arr[j] > arr[j + 1]){
                ans.push_back({arr[j], arr[j + 1]});
                used[arr[j]][arr[j + 1]] = true;
                used[arr[j + 1]][arr[j]] = true;
                swap(arr[j], arr[j + 1]);
            }else{
                if(used[arr[j]][arr[j + 1]] || used[arr[j + 1]][arr[j]]){

                }else{
                    ans.push_back({arr[j], arr[j + 1]});
                    ans.push_back({arr[j + 1], arr[j]});
                    used[arr[j]][arr[j + 1]] = true;
                    used[arr[j + 1]][arr[j]] = true;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans.size()<<endl;
    for(auto x : ans){
        cout<<x.first<<" "<<x.second<<endl;
    }
    return 0;
}

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = i - 1;j > 0;j--){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = n;j > i;j--){
            if(arr[j] > arr[i]) ans.push_back({arr[i], arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<vector<bool>> used(n + 1, vector<bool>(n + 1, false));
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < n;j++){
            if(arr[j] > arr[j + 1]){
                ans.push_back({arr[j], arr[j + 1]});
                used[arr[j]][arr[j + 1]] = true;
                used[arr[j + 1]][arr[j]] = true;
                swap(arr[j], arr[j + 1]);
            }else{
                if(used[arr[j]][arr[j + 1]] || used[arr[j + 1]][arr[j]]){

                }else{
                    ans.push_back({arr[j], arr[j + 1]});
                    ans.push_back({arr[j + 1], arr[j]});
                    used[arr[j]][arr[j + 1]] = true;
                    used[arr[j + 1]][arr[j]] = true;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans.size()<<endl;
    for(auto x : ans){
        cout<<x.first<<" "<<x.second<<endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
const int INF = 1e18;
int a[200005],b[200005];
min_heap<int>q;
void solve()
{
    int n,m;
    cin >> n >> m;
    while(q.size()) q.pop();
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        q.push(a[i]);
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> b[i];
    }
    sort(b+1,b+m+1);
    //if(n == 5)  cout << m << endl;
    int l = 1;
    while(q.size() && l <= m)
    {
        int tmp1,tmp2;
        tmp1 = q.top();
        
        q.pop();
        if(tmp1 == b[l])    {l++;continue;}
        tmp2 = q.top();
        q.pop();
        //cout << tmp1 << ' ' << tmp2 << endl;
        if(tmp2 - tmp1 <= 1)    q.push(tmp1 + tmp2);
        else
        {
            cout << "No" << endl;
            return ;
        }
    }
    
    if(l == m+1 && q.empty()) cout << "Yes" << endl;
    else    cout << "No" << endl;
    return;
}

signed main() 
{
    //ios::sync_with_stdio(false),cin.tie(0);
    int tt;
    cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
const int INF = 1e18;
int a[200005],b[200005];
min_heap<int>q;
void solve()
{
    int n,m;
    cin >> n >> m;
    while(q.size()) q.pop();
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        q.push(a[i]);
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> b[i];
    }
    sort(b+1,b+m+1);
    //if(n == 5)  cout << m << endl;
    int l = 1;
    while(q.size() && l <= m)
    {
        int tmp1,tmp2;
        tmp1 = q.top();
        
        q.pop();
        if(tmp1 == b[l])    {l++;continue;}
        if(q.size() == 0)
        {
            cout << "No" << endl;
            return ;
        }   
        tmp2 = q.top();
        q.pop();
        //cout << tmp1 << ' ' << tmp2 << endl;
        if(tmp2 - tmp1 <= 1)    q.push(tmp1 + tmp2);
        else
        {
            cout << "No" << endl;
            return ;
        }
    }
    
    if(l == m+1 && q.empty()) cout << "Yes" << endl;
    else    cout << "No" << endl;
    return;
}

signed main() 
{
    //ios::sync_with_stdio(false),cin.tie(0);
    int tt;
    cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
const int INF = 1e18;
int a[200005],b[200005];
min_heap<int>q;
void solve()
{
    int n,m;
    cin >> n >> m;
    while(q.size()) q.pop();
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        q.push(a[i]);
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> b[i];
    }
    sort(b+1,b+m+1);
    //if(n == 5)  cout << m << endl;
    int l = 1;
    while(q.size() && l <= m)
    {
        int tmp1,tmp2;
        tmp1 = q.top();
        
        q.pop();
        if(tmp1 == b[l])    {l++;continue;}
        if(q.size() == 0)
        {
            cout << "No" << endl;
            return ;
        }   
        tmp2 = q.top();
        q.pop();
        //cout << tmp1 << ' ' << tmp2 << endl;
        if(tmp2 - tmp1 <= 1)    q.push(tmp1 + tmp2);
        else
        {
            cout << "No" << endl;
            return ;
        }
    }
    
    if(l == m+1 && q.empty()) cout << "Yes" << endl;
    else    cout << "No" << endl;
    return;
}

signed main() 
{
    //ios::sync_with_stdio(false),cin.tie(0);
    int tt;
    cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n' 
#define int long long
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
const int INF = 1e18;
void solve()
{
    max_heap<int>a,b;
    int n,m,x,sum = 0;
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
    {
        cin >> x;
        a.push(x);
        sum += x;
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> x;
        b.push(x);
        sum -= x;
    }
    if(sum)
    {
        cout << "No" << endl;
        return ;
    }
    while(a.size() && b.size())
    {
        int aa = a.top(),bb = b.top();
        //cout << aa << ' ' << bb << endl;
        if(aa > bb)
        {
            cout << "No" << endl;
            return ;
        }
        if(aa == bb)
        {
            a.pop();
            b.pop();
        }
        if(aa < bb)
        {
            b.pop();
            b.push(bb/2);
            b.push((bb+1)/2);
        }
    }
    //cout << a.size() << ' ' << b.size() << endl;
    if(a.empty() && b.empty())  cout << "Yes" << endl;
    else    cout << "No" << endl;
    return;
}
signed main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    int tt = 1;
    cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
const int INF = 1e18;
int a[200005],b[200005];
min_heap<int>q;
void solve()
{
    int n,m;
    cin >> n >> m;
    while(q.size()) q.pop();
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        q.push(a[i]);
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> b[i];
    }
    sort(b+1,b+m+1);
    //if(n == 5)  cout << m << endl;
    int l = 1;
    while(q.size() && l <= m)
    {
        int tmp1,tmp2;
        tmp1 = q.top();
        
        q.pop();
        if(tmp1 == b[l])    {l++;continue;}
        tmp2 = q.top();
        q.pop();
        //cout << tmp1 << ' ' << tmp2 << endl;
        if(tmp2 - tmp1 <= 1)    q.push(tmp1 + tmp2);
        else
        {
            cout << "No" << endl;
            return ;
        }
    }
    
    if(l == m+1 && q.empty()) cout << "Yes" << endl;
    else    cout << "No" << endl;
    return;
}

signed main() 
{
    //ios::sync_with_stdio(false),cin.tie(0);
    int tt;
    cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}