/*
	[NWERC'10] RANKINGS
	by: Jan Kuipers
*/

#include <iostream>
#include <vector>

using namespace std;

int main () {

	int runs;
	cin >> runs;

	while (runs--) {

		int N;
		cin >> N;

		vector<int> oldrank(N);
		
		for (int i=0; i<N; i++) {
			int x;
			cin >> x;
			oldrank[x-1] = i;
		}

		int S;
		cin >> S;

		vector<int> newrank = oldrank;

		for (int i=0; i<S; i++) {
			int x,y;
			cin >> x >> y;
			x--; y--;
			
			if (oldrank[x] < oldrank[y]) {
				newrank[x]++;
				newrank[y]--;
			}
			else {
				newrank[x]--;
				newrank[y]++;
			}
		}

		bool ok=true;
		vector<int> sol(N,0);

		for (int i=0; i<N; i++) {
			if (sol[newrank[i]] > 0) ok=false;
			sol[newrank[i]] = i+1;
		}

		if (!ok)
			cout << "IMPOSSIBLE" << endl;
		else {
			for (int i=0; i<N-1; i++)
				cout << sol[i] << " ";
			cout << sol[N-1] << endl;
		}
	}

	return 0;
}
