#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9 + 7;
int dp[107][107];
int par[107][107];
string t = ".,!? ";
bool check(char c) { return t.find(c) == string::npos; }
void solve() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n;
    cin >> n;
    vector<string> users;
    for (int i = 0; i < n; i++) {
      string p;
      cin >> p;
      users.push_back(p);
    }
    sort(users.begin(), users.end());
    map<string, int> id;
    for (int i = 0; i < n; i++) id[users[i]] = i;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) dp[0][i] = 1;
    memset(par, -1, sizeof(par));
    int m;
    cin >> m;
    string buf;
    getline(cin, buf);
    vector<string> message;
    for (int i = 0; i < m; i++) {
      string buf;
      getline(cin, buf);
      int pos = buf.find(':');
      string user = buf.substr(0, pos);
      string msg = buf.substr(pos + 1);
      message.push_back(msg);
      vector<string> w;
      int p = 0, l = msg.size();
      while (p < l) {
        while (p < l && !check(msg[p])) p++;
        int q = p;
        while (q < l && check(msg[q])) q++;
        string word = msg.substr(p, q - p);
        if (word != "") w.push_back(word);
        p = q;
      }
      int uid = id.count(user) == 0 ? -1 : id[user];
      if (uid == -1) {
        for (int j = 0; j < n; j++) {
          if (find(w.begin(), w.end(), users[j]) != w.end()) continue;
          for (int jj = 0; jj < n; jj++) {
            if (dp[i][jj] == 1 && (i == 0 || j != jj)) {
              dp[i + 1][j] = 1;
              par[i + 1][j] = jj;
            }
          }
        }
      } else {
        for (int jj = 0; jj < n; jj++) {
          if (dp[i][jj] == 1 && (i == 0 || uid != jj)) {
            dp[i + 1][uid] = 1;
            par[i + 1][uid] = jj;
          }
        }
      }
    }
    vector<string> res;
    for (int i = 0; i < n; i++)
      if (dp[m][i] == 1) {
        int p = i, q = m;
        while (q > 0) {
          res.push_back(users[p]);
          p = par[q][p];
          q--;
        }
      }
    if (res.empty()) {
      cout << "Impossible" << '\n';
    } else {
      reverse(message.begin(), message.end());
      for (int i = m - 1; i >= 0; --i) {
        ostringstream oss;
        oss << res[i];
        oss << ":";
        oss << message[i];
        cout << oss.str() << '\n';
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(9);
  cout << fixed;
  solve();
  return 0;
}
