// NWERC'10 solution for problem 'rankings'
// Jaap Eldering

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main()
{
	int run, nruns;

	cin >> nruns;

	for(run=1; run<=nruns; run++) {
		int n, m, team, a, b;
		cin >> n;
		VI oldrank(n,-1), newrank;
		for(int i=0; i<n; i++) {
			cin >> team;
			team--;
			if ( oldrank[team]!=-1 ) return 1;
			oldrank[team] = i;
		}
		newrank = oldrank;
		cin >> m;
		VVI swap(n,VI(n,1));
		for(int i=0; i<m; i++) {
			cin >> a >> b;
			--a; --b;
			if ( swap[a][b]!=1 ) return 1;
			swap[a][b] = swap[b][a] = -1;
			if ( oldrank[a]<oldrank[b] ) {
				newrank[a]++;
				newrank[b]--;
			} else {
				newrank[a]--;
				newrank[b]++;
			}
		}
		VI order(n);
		for(int i=0; i<n; i++) order[newrank[i]] = i+1;

		int valid = 1;
		for(a=0; a<n; a++)
			for(b=0; b<a; b++)
				if ( (newrank[a]-newrank[b])*
				     (oldrank[a]-oldrank[b])*swap[a][b]<=0 ) valid = 0;

		if ( valid ) {
			for(int i=0; i<n-1; i++) cout << order[i] << ' ';
			cout << order[n-1] << endl;
		} else {
			cout << "IMPOSSIBLE" << endl;
		}
	}

	return 0;
}
