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


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

using namespace std;

void inline solve() {
    int l, r;
    cin >> l >> r;
    int a = l;
    int b = 0;
    int c = 0;
    for (int i = 30; i >= 0; --i) {
        if (a & (1 << i)) continue;
        if ((b | (1 << i)) > r) continue;
        b |= 1 << i;
    }
    if (b < l) b = l+1;
    for (int i = 30; i >= 0; --i) {
        if (b & (1 << i)) continue;
        if ((c | (1 << i)) > r) continue;
        c |= 1 << i;
    }
    if (c < l) c = l;
    while (c == a || c == b) ++c;
    cout << a << ' ' << b << ' ' << c << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    cin >> t;
    while (t--) solve();

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> v(n);
        ll maxi=INT_MIN;
        for(ll i=0; i<n; i++){
            cin>>v[i];
            maxi=max(maxi, v[i]);
        }      
        vector<ll> hash(maxi+1, 0);
        for(ll i=0; i<n; i++) hash[v[i]]++;
        sort(hash.begin(), hash.end());
        if(k==0){
            ll ans=0;
            for(int i=0; i<hash.size(); i++){
                if(hash[i]!=0) ans++;
            }
            cout<<ans<<endl;
            continue;
        }
        bool isDone=false;
        for(ll i=1; i<hash.size()-1; i++){
            if(k>=hash[i]) k=k-hash[i];
            else {
                cout<<hash.size()-i<<endl;
                isDone=true;
                break;
            }
        }
        if(!isDone){
            cout<<1<<endl;
        }
    }    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> v(n);
        ll maxi=INT_MIN;
        for(ll i=0; i<n; i++){
            cin>>v[i];
            maxi=max(maxi, v[i]);
        }      
        vector<ll> hash(maxi+1, 0);
        for(ll i=0; i<n; i++) hash[v[i]]++;
        sort(hash.begin(), hash.end());
        // if(k==0){
        //     ll ans=0;
        //     for(int i=0; i<hash.size(); i++){
        //         if(hash[i]!=0) ans++;
        //     }
        //     cout<<ans<<endl;
        //     continue;
        // }
        bool isDone=false;
        for(ll i=1; i<hash.size()-1; i++){
            if(k>=hash[i]) k=k-hash[i];
            else {
                cout<<hash.size()-i<<endl;
                isDone=true;
                break;
            }
        }
        if(!isDone){
            cout<<1<<endl;
        }
    }    
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> v(n);
        for(ll i=0; i<n; i++){
            cin>>v[i];            
        }      
        sort(v.begin(), v.end());
        vector<int> hash = {1};
        for(ll i=1; i<n; i++){
            if(v[i]==v[i-1]){
                hash.back()++;
            } else {
                hash.push_back(1);
            }
        }
        bool isDone = true;
        sort(hash.begin(), hash.end());
        for(int i=0; i<hash.size()-1; i++){
            if(k>=hash[i]) k=k-hash[i];
            else {
                cout<<hash.size()-i<<endl;
                isDone=false;
                break;
            }
        }
        if(isDone){
            cout<<1<<endl;
        }
    }    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> v(n);
        ll maxi=INT_MIN;
        for(ll i=0; i<n; i++){
            cin>>v[i];
            maxi=max(maxi, v[i]);
        }      
        vector<ll> hash(maxi+1, 0);
        for(ll i=0; i<n; i++) hash[v[i]]++;
        sort(hash.begin(), hash.end());
        if(k==0){
            ll ans=0;
            for(int i=0; i<hash.size(); i++){
                if(hash[i]!=0) ans++;
            }
            cout<<ans<<endl;
            continue;
        }
        bool isDone=false;
        for(ll i=1; i<hash.size()-1; i++){
            if(k>=hash[i]) k=k-hash[i];
            else {
                cout<<hash.size()-i<<endl;
                isDone=true;
                break;
            }
        }
        if(!isDone){
            cout<<1<<endl;
        }
    }    
    return 0;
}

Submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<ll> v(n);
        ll maxi=INT_MIN;
        for(ll i=0; i<n; i++){
            cin>>v[i];
            maxi=max(maxi, v[i]);
        }      
        vector<ll> hash(maxi+1, 0);
        for(ll i=0; i<n; i++) hash[v[i]]++;
        sort(hash.begin(), hash.end());
        // if(k==0){
        //     ll ans=0;
        //     for(int i=0; i<hash.size(); i++){
        //         if(hash[i]!=0) ans++;
        //     }
        //     cout<<ans<<endl;
        //     continue;
        // }
        bool isDone=false;
        for(ll i=1; i<hash.size()-1; i++){
            if(k>=hash[i]) k=k-hash[i];
            else {
                cout<<hash.size()-i<<endl;
                isDone=true;
                break;
            }
        }
        if(!isDone){
            cout<<1<<endl;
        }
    }    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
from collections import Counter
def solve(a,n,k):
    a.sort()
    cnt = Counter(a)
    counts = sorted(cnt.values())
    m = len(counts)
    print(cnt)
    print(counts)
    for i in range(m - 1):
        if counts[i] > k:
            print(m - i)
            return
        k -= counts[i]
    
    print(1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    solve(a,n,k)


Submission (verdict: Accepted):
from collections import Counter
def solve(a,n,k):
    a.sort()
    cnt = Counter(a)
    counts = sorted(cnt.values())
    m = len(counts)

    for i in range(m - 1):
        if counts[i] > k:
            print(m - i)
            return
        k -= counts[i]
    
    print(1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    solve(a,n,k)
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 9):
def f(a,n,k):
    b=[]
    c=[]
    for ch in a:
        if ch not in b:
            b.append(ch)
    for ch in b:
        c.append(a.count(ch))
    c.sort()
    i=0
    s=0
    while i<len(c) and s+c[i]<=k:
        s+=c[i]
        i+=1
    print(len(c)-i) if i<len(c) else print(len(c)-i+1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    f(a,n,k)

Submission (verdict: Time limit exceeded on test 17):
def f(a,n,k):
    b={}
    c=[]
    for ch in a:
        if ch not in b:
            b[ch]=1
        else:
            b[ch]+=1
    for ch in b:
        c.append(b[ch])
    c.sort()
    i=0
    s=0
    while i<len(c) and s+c[i]<=k:
        s+=c[i]
        i+=1
    print(len(c)-i) if i<len(c) else print(len(c)-i+1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    f(a,n,k)
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 17):
def f(a,n,k):
    b={}
    c=[]
    for ch in a:
        if ch not in b:
            b[ch]=1
        else:
            b[ch]+=1
    for ch in b:
        c.append(b[ch])
    c.sort()
    i=0
    s=0
    while i<len(c) and s+c[i]<=k:
        s+=c[i]
        i+=1
    print(len(c)-i) if i<len(c) else print(len(c)-i+1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    f(a,n,k)

Submission (verdict: Wrong answer on test 1):
from collections import Counter
def solve(a,n,k):
    a.sort()
    cnt = Counter(a)
    counts = sorted(cnt.values())
    m = len(counts)
    print(cnt)
    print(counts)
    for i in range(m - 1):
        if counts[i] > k:
            print(m - i)
            return
        k -= counts[i]
    
    print(1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    solve(a,n,k)
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64


Submission (verdict: Time limit exceeded on test 9):
def f(a,n,k):
    b=[]
    c=[]
    for ch in a:
        if ch not in b:
            b.append(ch)
    for ch in b:
        c.append(a.count(ch))
    c.sort()
    i=0
    s=0
    while i<len(c) and s+c[i]<=k:
        s+=c[i]
        i+=1
    print(len(c)-i) if i<len(c) else print(len(c)-i+1)
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    f(a,n,k)
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

using i64 = long long;


int main(){

    int tt;
    cin >> tt;
    while(tt --){
        int n;
        cin >> n;
        vector<int> a(n);
        i64 ans = 0LL;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            ans += a[i];
        }
        while((int)a.size() > (int)0){
            vector<int> d((int)a.size() - 1);
            i64 tot = 0;
            for(int i = 0;i < (int)a.size() - 1;i++){
                d[i] = a[i + 1] - a[i];
                tot += d[i];
            }
            ans = max(tot,ans);
            ans = max(ans,tot * -1LL);
            a = d;
        }

        cout << ans << '\n';
    }

    return 0;
}

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

using i64 = long long;


int main(){

    int tt;
    cin >> tt;
    while(tt --){
        int n;
        cin >> n;
        vector<int> a(n);
        i64 ans = 0LL;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            ans += a[i];
        }
        while((int)a.size() > (int)1){
            vector<int> d((int)a.size() - 1);
            i64 tot = 0;
            for(int i = 0;i < (int)a.size() - 1;i++){
                d[i] = a[i + 1] - a[i];
                tot += d[i];
            }
            ans = max(tot,ans);
            ans = max(ans,tot * -1LL);
            a = d;
        }

        cout << ans << '\n';
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


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

using i64 = long long;


int main(){

    int tt;
    cin >> tt;
    while(tt --){
        int n;
        cin >> n;
        vector<int> a(n);
        i64 ans = 0LL;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            ans += a[i];
        }
        while((int)a.size() > (int)0){
            vector<int> d((int)a.size() - 1);
            i64 tot = 0;
            for(int i = 0;i < (int)a.size() - 1;i++){
                d[i] = a[i + 1] - a[i];
                tot += d[i];
            }
            ans = max(tot,ans);
            ans = max(ans,tot * -1LL);
            a = d;
        }

        cout << ans << '\n';
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

using i64 = long long;


int main(){

    int tt;
    cin >> tt;
    while(tt --){
        int n;
        cin >> n;
        vector<int> a(n);
        i64 ans = 0LL;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            ans += a[i];
        }
        while((int)a.size() > (int)1){
            vector<int> d((int)a.size() - 1);
            i64 tot = 0;
            for(int i = 0;i < (int)a.size() - 1;i++){
                d[i] = a[i + 1] - a[i];
                tot += d[i];
            }
            ans = max(tot,ans);
            ans = max(ans,tot * -1LL);
            a = d;
        }

        cout << ans << '\n';
    }

    return 0;
}

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

using i64 = long long;


int main(){

    int tt;
    cin >> tt;
    while(tt --){
        int n;
        cin >> n;
        vector<i64> a(n);
        i64 ans = 0LL;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            ans += a[i];
        }
        while((int)a.size() > (int)1){
            vector<i64> d((int)a.size() - 1);
            i64 tot = 0;
            for(int i = 0;i < (int)a.size() - 1;i++){
                d[i] = a[i + 1] - a[i];
                tot += d[i];
            }
            ans = max(tot,ans);
            ans = max(ans,tot * -1LL);
            a = d;
        }

        cout << ans << '\n';
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string ans;
        int cnt=0;
        while(ans.size()!=s.size()){
            int maxi=0;
            int index;
        for(int i=cnt;i<s.size();++i){
            if((s[i]-'0')-(i-cnt)>maxi){
                maxi=((s[i]-'0')-(i-cnt));
                index=i;
            }
        }
        while(index>cnt){
            swap(s[index],s[index-1]);
            index--;
        }
        ans=ans+to_string(maxi);
        cnt++;
        }
        cout<<ans<<endl;
    }
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string ans;
        int cnt=0;
        while(ans.size()!=s.size()){
            int maxi=0;
            int index;
        for(int i=cnt;i<min(i+10,(int)s.size());++i){
            if((s[i]-'0')-(i-cnt)>maxi){
                maxi=((s[i]-'0')-(i-cnt));
                index=i;
            }
        }
        while(index>cnt){
            swap(s[index],s[index-1]);
            index--;
        }
        ans=ans+to_string(maxi);
        cnt++;
        }
        cout<<ans<<endl;
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string ans;
        int cnt=0;
        while(ans.size()!=s.size()){
            int maxi=0;
            int index;
        for(int i=cnt;i<min(i+10,(int)s.size());++i){
            if((s[i]-'0')-(i-cnt)>maxi){
                maxi=((s[i]-'0')-(i-cnt));
                index=i;
            }
        }
        while(index>cnt){
            swap(s[index],s[index-1]);
            index--;
        }
        ans=ans+to_string(maxi);
        cnt++;
        }
        cout<<ans<<endl;
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s; 
        for (int i = 0; i < s.size(); i++) {
            int best = s[i] - '0', pos = i;
            for (int j = i; j < min(i + 10, (int)s.size()); j++) {
                if (s[j] - '0' - (j - i) > best) {
                    best = s[j] - '0' - (j - i);
                    pos = j;
                }
            }
            while (pos > i) {
                swap(s[pos], s[pos - 1]);
                pos--;
            }
            s[i] = char(best + '0');
        }
        cout << s << '\n';
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string ans;
        int cnt=0;
        while(ans.size()!=s.size()){
            int maxi=0;
            int index;
        for(int i=cnt;i<s.size();++i){
            if((s[i]-'0')-(i-cnt)>maxi){
                maxi=((s[i]-'0')-(i-cnt));
                index=i;
            }
        }
        while(index>cnt){
            swap(s[index],s[index-1]);
            index--;
        }
        ans=ans+to_string(maxi);
        cnt++;
        }
        cout<<ans<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using pbds= tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define vi vector<int>
#define eb emplace_back
#define pb push_back
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a; i<b; i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(long double t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}


int isprime(int n)
{
    int a = sqrt(n);
    int i;
    for (i = 2; i <= a; i++){
        if (n % i == 0){
            return 0;
        }
    }
    if (i == a + 1){
        return 1;
    }
    return 0;
}


main()
{
    IOS;

    int t; cin>>t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int ans = accumulate(a.begin(), a.end(), 0);
        while (a.size() > 1) {
            vector<int> b(a.size() - 1);
            for (int i = 0; i < a.size() - 1; i++) {
                b[i] = a[i + 1] - a[i];
            }
            swap(a, b);
            ans = max(ans, (int)abs(accumulate(a.begin(), a.end(), 0)));
        }
        cout << ans << endl;

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

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n);

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

        v[i] = (i % 3);

    }



    if(n % 3 != 0) {

        v[n - 1] = 1;

        v[n - 2] = 0;

    }



    int l = (x - 1 + n) % n;

    int r = (x + 1) % n;



    if(y != l && y != r) {

        if(v[x] == v[y] && v[y] == 1) {

            if(x > y ) swap(x, y);

            v[x] = 2;

            v[(x + 1) % n] = 1;

            if(n % 3 == 1) v[y] = 2;

        }

    }







    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";

}          

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

}

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n, -1);

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

        v[(x + i) % n] = i % 2;

    }



    if(n & 1 || (x - y) % 2 == 0) v[x] = 2;



    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";



    

}          

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

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

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n);

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

        v[i] = (i % 3);

    }



    if(n % 3 != 0) {

        v[n - 1] = 1;

        v[n - 2] = 0;

    }



    int l = (x - 1 + n) % n;

    int r = (x + 1) % n;



    set<int> st = {v[l], v[r], v[y]};

    int mex = 0;

    while(st.count(mex)) mex++;



    if(v[x] != mex) {

        v[x] = mex;

    }



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

        if(i == x || i == y) continue;

        st.clear();

        l = (i - 1 + n) % n;

        r = (i + 1) % n;

        st.insert(v[l]);

        st.insert(v[r]);

        int mex = 0;

        while(st.count(mex)) mex++;

        if(v[i] != mex) v[i] = mex;

    }



    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";

}          

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

}

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n);

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

        v[i] = (i % 3);

    }



    if(n % 3 != 0) {

        v[n - 1] = 1;

        v[n - 2] = 0;

    }



    int l = (x - 1 + n) % n;

    int r = (x + 1) % n;



    if(y != l && y != r) {

        if(v[x] == v[y] && v[y] == 1) {

            if(x > y ) swap(x, y);

            if(n % 3 == 2) {

                v[x] = 2;

                v[(x + 1) % n] = 1;

            }

            else {

                v[x] = 3;

                v[(x + 1) % n] = 1;

                if(n % 3 == 1) v[y] = 2;

            }

        }

    }







    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";

}          

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

}