// Author : Chi
// created :
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <pair<int,int>, null_type, greater<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define ai(a)       for(auto &i:a)cin>>i;
#define ao(a)       for(auto i:a)cout<<i<<' ';
#define TEST1       solve();
#define mod         1000000007
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
void solve(){
    int n,d,k;
    cin>>n>>d>>k;
    if(d>=n){
        cout<<"NO\n";
        return;
    }
    vector<int>deg(n);
    vector<pair<int,int>>ans;
    set<pair<int,int>>q;
    for(int i=0;i<d;++i){
        ++deg[i];
        ++deg[i+1];
        if(deg[i]>k||deg[i+1]>k){
            cout<<"NO\n";
            return;
        }
        ans.push_back({i,i+1});
        }
        for(int i=1;i<d;i++)
            q.insert({max(i,d-i),i});
        for(int i = d+1;i<n;++i){
            while(!q.empty() && deg[q.begin()->ss]==k)
                q.erase(q.begin());
            if(q.empty()||q.begin()->ff==d){
                cout<<"NO\n";
                return;
            }
            ++deg[i];
            ++deg[q.begin()->second];
            ans.push_back({i,q.begin()->ss});
            q.insert({q.begin()->ff+1,i});
        }
        cout<<"YES\n";
        for(auto i:ans){
            cout<<i.ff<< " "<<i.ss<< "\n";
        }
}
// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}
