#include <iostream>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <string>
using namespace std;


long long readInt(long long l,long long r,char endd){
	long long x=0;
	int cnt=0;
	int fi=-1;
	bool is_neg=false;
	while(true){
		char g=getchar();
		if(g=='-'){
			assert(fi==-1);
			is_neg=true;
			continue;
		}
		if('0'<=g && g<='9'){
			x*=10;
			x+=g-'0';
			if(cnt==0){
				fi=g-'0';
			}
			cnt++;
			assert(fi!=0 || cnt==1);
			assert(fi!=0 || is_neg==false);
			
			assert(!(cnt>19 || ( cnt==19 && fi>1) ));
		} else if(g==endd){
			assert(cnt>0);
			if(is_neg){
				x= -x;
			}
			assert(l<=x && x<=r);
			return x;
		} else {
			assert(false);
		}
	}
}
string readString(int l,int r,char endd){
	string ret="";
	int cnt=0;
	while(true){
		char g=getchar();
		assert(g!=-1);
		if(g==endd){
			break;
		}
		cnt++;
		ret+=g;
	}
	assert(l<=cnt && cnt<=r);
	return ret;
}
long long readIntSp(long long l,long long r){
	return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
	return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
	return readString(l,r,'\n');
}
string readStringSp(int l,int r){
	return readString(l,r,' ');
}


int T;
int n;
int sm_n=0;
vector<int> adj[200200];
bool vis[200200];


void dfs_tree(int nd){
	vis[nd]=true;
	for(int i=0;i<adj[nd].size();i++){
		int ch=adj[nd][i];
		if(vis[ch])continue;
		dfs_tree(ch);
	}
}
int list[200200][4],f=0;
int dp[200200];
bool ok;
void dfs(int nd,int p){
	int a=-1,b=-1;
	for(int i=0;i<adj[nd].size();i++){
		int ch=adj[nd][i];
		if(ch==p)continue;
		dfs(ch,nd);
		if(dp[ch] == false){
			if(a==-1){
				a=ch;
			} else if(b==-1){
				b=ch;
			} else{
				list[f][0] = nd;
				list[f][1] = a;
				list[f][2] = b;
				list[f][3] = ch;
				a=-1;
				b=-1;
				f++;
			}
		}
	}
	if(a != -1 && b != -1){
		list[f][0] = nd;
		list[f][1] = a;
		list[f][2] = b;
		list[f][3] = p;
		f++;
		dp[nd]=true;
	} else if(a == -1 && b == -1){
		dp[nd]=false;
	} else {
		ok=false;
	}
}
int main(){
	T=readIntLn(1,100);
	while(T--){
		n=readIntLn(2,200000);
		for(int i=1;i<=n;i++){
			vis[i]=false;
			adj[i].clear();
		}
		f=0;
		ok=true;
		for(int i=1;i<n;i++){
			int a,b;
			a=readIntSp(1,n);
			b=readIntLn(1,n);
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		dfs_tree(1);
		for(int i=1;i<=n;i++){
			assert(vis[i]);
		}
		if((n-1)% 3){
			printf("NO\n");
			continue;
		}
		dfs(1,1);
		if(!ok || dp[1]){
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		for(int i=0;i<f;i++){
			printf("%d %d %d %d\n",list[i][0],list[i][1],list[i][2],list[i][3]);
		}
	}
	assert(getchar()==-1);
}