Link to this code:
https://cses.fi/paste/40fad8955180834ac5ea97/#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int mod=998244353;
typedef pair<int, int> pii;
const ll INF = 1e18;
ll lcm(ll a, ll b) {
return (a / __gcd(a, b)) * b;
}
ll gcd(ll a, ll b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct VectorHash {
size_t operator()(const vector<ll>& v) const {
std::hash<ll> hasher;
size_t seed = 0;
for (ll i : v) {
seed ^= hasher(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
};
ll poweroftwo(ll x) {
ll cnt = 0;
while (x % 2 == 0) {
x /= 2;
cnt++;
}
return cnt;
}
ll myPow(ll x, ll n) {
if (n == 0)
return 1;
if (n < 0)
return 1 / myPow(x, -n);
if (n % 2 == 1)
return (x * myPow(x, n - 1)) % mod;
ll temp = myPow(x * x % mod, n / 2) % mod;
return (temp + mod) % mod;
}
ll lcs(string X, string Y, int m, int n)
{
// Initializing a matrix of size
// (m+1)*(n+1)
int L[m + 1][n + 1];
// Following steps build L[m+1][n+1]
// in bottom up fashion. Note that
// L[i][j] contains length of LCS of
// X[0..i-1] and Y[0..j-1]
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 || j == 0)
L[i][j] = 0;
else if (X[i - 1] == Y[j - 1])
L[i][j] = L[i - 1][j - 1] + 1;
else
L[i][j] = max(L[i - 1][j], L[i][j - 1]);
}
}
// L[m][n] contains length of LCS
// for X[0..n-1] and Y[0..m-1]
return L[m][n];
}
vector<bool>prime(1e4,true);
void seive(){
prime[0]=false;
prime[1]=false;
for(int i=2;i*i<=1e4;i++){
if(prime[i]){
for(int j=i*i;j<=1e4;j+=i){
prime[j]=false;
}
}
}
}
vector<int> z_function(string s) {
int n = s.size();
vector<int> z(n);
int l = 0, r = 0;
for(int i = 1; i < n; i++) {
if(i < r) {
z[i] = min(r - i, z[i - l]);
}
while(i + z[i] < n && s[z[i]] == s[i + z[i]]) {
z[i]++;
}
if(i + z[i] > r) {
l = i;
r = i + z[i];
}
}
return z;
}
ll digit_sum(ll n) {
int ret = 0;
while(n) {
ret += n % 10;
n /= 10;
}
return ret;
}
bool ispalindrome(string s){
for(int i=0;i<s.length()/2;i++){
if(s[i]!=s[s.length()-i-1]){
return false;
}
}
return true;
}
ll maxSubArray(vector<ll>& nums) {
ll csum=0;
ll msum=LLONG_MIN;
for(int i=0;i<nums.size();i++){
csum += nums[i];
msum=max(msum,csum);
if(csum<0)
{
csum=0;
}
}
return msum;
}
struct DSU{
vector<ll>parent,size;
DSU(ll n){
parent.resize(n);
size.resize(n,1);
for(int i=0;i<n;i++){
parent[i]=i;
}
}
ll find(ll a){
if(parent[a]==a) return a;
return parent[a]=find(parent[a]);
}
void unite(ll a,ll b){
ll x=find(a);
ll y=find(b);
if(x==y) return;
if(size[x]>size[y]){
size[x]+=size[y];
parent[y]=x;
}
else{
size[y]+=size[x];
parent[x]=y;
}
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output2.txt","w",stdout);
#endif
ll t;
cin>>t;
while(t--){
ll n,a,b;
cin>>n>>a>>b;
// just by trying out something,
// i made a pattern in terms of cycles
// suppose if i can make a cycle of length k
// k=a+b, then i can distribute a,b from that cycle
// and remaining will be draws
// eg k=a+b=1+2=3
// lets create cycle from 1,2,3
// 1->2->3->1
// now edges are
// 1,2 2,3 3,1
// here 2 edges have v > u
// 4,4 draw
// does this work for every a+b ?
// n=5 a=2,b=3
// 1->2->3->4->5->1
// 1,2 2,3 3,4 4,5 5,1
// i can flip some edges to compensate
// 1,2 2,3
// 4,3 5,4 5,1
// nope 3,5 cant be played twice by same person
// i think there can be multiple cycles
// basically i am breaking in cycles so that in each cycle
// the lower person wins 1 and rest other wins
// eg a=2,b=3
// 1st cycle 1,1
// 2nd cycle 1,2
// so 1,n is always possible
// there should be atleast 1 cycle
// and for that need atleast 1 win by both
//ll draws=n-a-b;
if (a + b > (n) || (a == 0 && b > 0) || (b == 0 && a > 0)) {
cout << "NO" << endl;
continue;
}
ll oga=a;
ll ogb=b;
if(a>b) swap(a,b);
cout << "YES" << endl;
vector<ll> seq1(n), seq2(n);
for (int i = 0; i < n; i++) {
seq1[i] = i + 1;
seq2[i] = i + 1;
}
// Perform a-1 swaps on seq2 at (0,1), (2,3), ...
ll cnt = 0;
ll i = 0;
while (i + 1 < n && cnt < a - 1) {
swap(seq2[i], seq2[i + 1]);
i += 2;
cnt++;
}
// Rotate from index 2*(a-1) to a+b-1
if (a >= 1 && b >= 1) {
ll start = 2 * (a - 1);
ll end = a + b - 1;
if (start < n && end < n && start <= end) {
rotate(seq2.begin() + start, seq2.begin() + start + 1, seq2.begin() + end + 1);
}
}
//cout<<oga<<" "<<ogb<<endl;
// Output: seq1 then seq2 if a < b, else seq2 then seq1
if (oga < ogb) {
for (int i = 0; i < n; i++) cout << seq1[i] << " ";
cout << endl;
for (int i = 0; i < n; i++) cout << seq2[i] << " ";
} else {
for (int i = 0; i < n; i++) cout << seq2[i] << " ";
cout << endl;
for (int i = 0; i < n; i++) cout << seq1[i] << " ";
}
cout << endl;
}
return 0;
}