#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<queue>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<bitset>
#include<string>
#include<cstdio>
#include<map>
#include<iterator>
#include<iomanip>
#define prfs(x) printf("%s\n",x.c_str())
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ;i++)
#define blop(i,n) for(int i = n-1 ; i>=0;i--)
#define M_P make_pair
#define All(X) (X).begin(),(X).end()
#define SZ(n) (int)(n).size()
#define voi vector<int>
#define vos vector<string>
#define vob vector<bool>
#define vovi vector<vector<int > >
#define vob vector<bool>
#define ll long long
using namespace std;
map<string, int> person, club, party;
int matrix[1300][1300];
int n = 2;
int p[1300];
int f = 0;
int ID(string one,int a) {
if (a == 1) {
if (!person[one])return person[one] = ++n;
return person[one];
}
else if (a == 2) {
if (!club[one])return club[one] = ++n;
return club[one];
}
if (!party[one])return party[one] = ++n;
return party[one];
}
void updatePath(int t, int minEdge) {
if (t == 1) {
f = minEdge;
return;
}
else if (p[t] != -1) {
updatePath(p[t], min(minEdge, matrix[p[t]][t]));
matrix[p[t]][t] -= f;
matrix[t][p[t]] += f;
}
}
int Ed(int s,int t) {
int mf = 0;
while (1) {
memset(p, -1, sizeof p);
f = 0;
queue<int> q;
q.push(1);
while (!q.empty()) {
int u = q.front();q.pop();
if (u == t)break;
for (int i = 1;i <= n;i++) {
if (p[i] == -1 && matrix[u][i] > 0) {
p[i] = u, q.push(i);
}
}
}
updatePath(t, (int)1e9);
if (!f)break;
mf += f;
}
return mf;
}
int main(){
freopen("src.txt", "r", stdin);
int T;
scanf("%d\n", &T);
string z;
while (T--) {
n = 2;
memset(matrix, 0, sizeof matrix);
party.clear(), club.clear(), person.clear();
while (getline(cin, z) && z.length() > 0) {
istringstream mycin(z);
string a, b;
mycin >> a >> b;
int ia = ID(a, 1), ip = ID(b, 3), ic;
matrix[ip][ia] = 1;
while (mycin >> b) {
ic = ID(b,2);
matrix[ia][ic] = 1;
matrix[ic][2] = 1;
}
}
int cl = club.size();
for (map<string,int>::iterator i = party.begin(); i!=party.end(); i++) {
matrix[1][i->second] = (cl-1) / 2;
}
int total = Ed(1,2);
if (total == cl) {
for (map<string, int>::iterator it1 = person.begin(); it1 != person.end();it1++) {
for (map<string, int>::iterator it2 = club.begin(); it2 != club.end();it2++) {
if (matrix[it2->second][it1->second]) {
printf("%s %s\n", it1->first.c_str(), it2->first.c_str());
}
}
}
}
else {
printf("Impossible.\n");
}
if (T)printf("\n");
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGU8c2V0PgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlPHNzdHJlYW0+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPHN0ZGlvLmg+CiNpbmNsdWRlPHN0YWNrPgojaW5jbHVkZTxkZXF1ZT4KI2luY2x1ZGU8Yml0c2V0PgojaW5jbHVkZTxzdHJpbmc+CiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8bWFwPgojaW5jbHVkZTxpdGVyYXRvcj4KI2luY2x1ZGU8aW9tYW5pcD4KI2RlZmluZSBwcmZzKHgpIHByaW50ZigiJXNcbiIseC5jX3N0cigpKQojZGVmaW5lIHByZmkoeCkgcHJpbnRmKCIlZFxuIix4KTsKI2RlZmluZSBzZmkoWCkgc2NhbmYoIiVkIiwmWCk7CiNkZWZpbmUgbG9wKGksbikgZm9yIChpbnQgaSA9IDAgOyBpIDwgbiA7aSsrKQojZGVmaW5lIGJsb3AoaSxuKSBmb3IoaW50IGkgPSBuLTEgOyBpPj0wO2ktLSkKI2RlZmluZSBNX1AgbWFrZV9wYWlyCiNkZWZpbmUgQWxsKFgpIChY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