#include<bits/stdc++.h>
using namespace std;
vector<int> dc1(int n, set<int> t[11]) {
vector<int> rm;
bool dq = false;
while(!dq) {
dq = true;
vector<pair<int,int>> tr;
for(int i = 1; i <= n; i++) {
if(t[i].size() != 0) dq = false;
if(t[i].size() == 1) {
rm.push_back(i);
for(auto u : t[i]) {
tr.push_back({u,i});
}
}
}
for(auto u : tr) {
t[u.first].erase(u.second);
t[u.second].erase(u.first);
}
}
if(rm.size() != n) {
set<int> jj;
for(int i = 1; i <= n; i++) {
jj.insert(i);
}
for(auto u : rm) jj.erase(u);
if(jj.size() != 0) {
for(auto u : jj) {
rm.push_back(u);
}
}
}
return rm;
}
int dist(set<int> t[11], int s, set<int> bt, int q) {
//cout << "DIST FROM " << s << " TO " << q << "\n";
if(bt.count(s)) { /*cout << "RTAV\n"*/; return 0; }
bt.insert(s);
if(s == q) {
//cout << "AT Q" << "\n";
return 1;
}
int ret = 0;
//cout << "SETSIZE " << t[s].size() << endl;
for(auto u : t[s]) {
//cout << "NEXT" << "\n";
ret += dist(t,u,bt,q);
}
if(ret > 0) ret++;
return ret;
}
int dd(set<int> t[11], int s, int q) {
unordered_set<int> bt;
return dist(t,s,bt,q)-1;
}
vector<int> dc2(int n, set<int> t[11]) {
vector<int> rm;
unordered_set<int> tc[11];
for(int i = 0; i < 11; i++) tc[i] = t[i];
bool dq = false;
while(!dq) {
dq = true;
vector<pair<int,int>> tr;
for(int i = 1; i <= n; i++) {
if(t[i].size() != 0) dq = false;
if(t[i].size() == 1) {
rm.push_back(i);
for(auto u : t[i]) {
tr.push_back({u,i});
}
}
}
for(auto u : tr) {
t[u.first].erase(u.second);
t[u.second].erase(u.first);
}
}
if(rm.size() != n) {
set<int> jj;
for(int i = 1; i <= n; i++) {
jj.insert(i);
}
for(auto u : rm) jj.erase(u);
if(jj.size() != 0) {
for(auto u : jj) {
rm.push_back(u);
}
}
}
//cout << "ERORDER" << "\n";
//for(auto u : rm) {
// cout << u << " ";
//}
//cout << endl;
vector<int> rv;
for(int i = 1; i < rm.size(); i++) {
//cout << "DIST BETWEEN " << rm[i-1] << " " << rm[i] << ": " << dd(tc,rm[i-1],rm[i]) << "\n";
rv.push_back(dd(tc,rm[i-1],rm[i]));
}
return rv;
}
int n;
vector<int> ok;
int tc = 1;
vector<pair<int,int>> vp;
void puugen(int j) {
if(j == n+1) {
unordered_set<int> t[11];
//cout << " ----- TREE " << tc << " -----\n";
/*for(auto u : vp) {
cout << u.first << " " << u.second << "\n";
}*/
//tc++;
//cout << " ------ END ---- \n";
for(auto u : vp) {
t[u.first].insert(u.second);
t[u.second].insert(u.first);
}
if(dc2(n,t) == ok) {
for(auto u : vp) {
cout << u.first << " " << u.second << "\n";
}
exit(0);
}
return;
}
if(1){
if(j == 1) {
1+1;
puugen(j+1);
}
else {
for(int i = 1; i < j; i++) {
vp.push_back({i,j});
puugen(j+1);
vp.pop_back();
}
}
}
}
int main() {
int t; cin>>t;
if(t == 1) {
cin >> n;
set<int> t[11];
for(int i = 0; i < n-1; i++) {
int a,b; cin >> a >> b;
t[a].insert(b);
t[b].insert(a);
}
vector<int> vs = dc1(n,t);
for(auto u : vs) {
cout << u << " ";
}
}
else {
cin >> n;
for(int i = 0; i < n-1; i++) {
int je; cin >> je;
ok.push_back(je);
}
puugen(1);
}
}