/* NWERC 2010: Sample solution to "Rankings"
 * Author: Sean Lip
 *
 * Algorithm: 
 * 
 * From the list of swaps, we can deduce the net change in position of a team
 * by counting how many swaps there are with teams originally above it and below
 * it. Add this net change to last year's rankings to get this year's rankings.
 * If there is a clash, the jury input is wrong. Finally, double-check whether
 * the generated ranking list produces the correct set of swaps.
 * 
 * Note: it can be shown, by induction, that a non-clash is a necessary and sufficient
 * condition for consistency of the input. 
 * 
 * The solution runs in O(N+S) time, where N is the number of teams and S is the number of swaps.
 */

#include <iostream>
#include <cstring>

using namespace std;

bool G[501][501];

int main()
{
	int T;
	cin >> T;
	for(int i = 0; i < T; i++)
	{
		memset(G,0,sizeof G);
		int n, orig[501];
		cin >> n;
		for(int j = 1; j <= n; j++)
		{
			int teamj;
			cin >> teamj;
			orig[teamj] = j;
		}
		
		int newRank[501];
		for(int j = 1; j <= n; j++)
			newRank[j] = orig[j];
		
		int m;
		cin >> m;
		for(int j = 0; j < m; j++)
		{
			int a,b;
			cin >> a >> b;
			
			if(a > b)
				cout << "ERROR: pair of the form (a, b) where a > b, in test case " << i+1 << endl;
			
			if(G[a][b] == 1)
			{
				cout << "ERROR: repeated pairs in input data in test case " << i+1 << endl;
				return 1;
			}
			G[a][b] = 1;
			
			if(orig[a] < orig[b])
				newRank[a]++, newRank[b]--;
			else if(orig[a] > orig[b])
				newRank[b]++, newRank[a]--;
			else
			{
				if(a == b)
					cout << "ERROR: pair of the form (a,a) in test case " << i+1 << endl;
				else
					cout << "ERROR: original input not a permutation, in test case " << i+1 << endl;
				return 1;
			}
		}
				
		int finalPos[501];
		memset(finalPos,0,sizeof finalPos);
		
		int imposs = 0;
		for(int j = 1; j <= n; j++)
		{
			if(finalPos[newRank[j]] != 0)
			{
				imposs = 1;
				break;
			}
			finalPos[newRank[j]] = j;
		}
		
		if(imposs)
			cout << "IMPOSSIBLE";
		else 
		{	
			for(int j = 1; j <= n; j++)
				if(j == 1) cout << finalPos[j];
				else cout << " " << finalPos[j];
		}
		cout << endl;
	}
	
	int tmp;
	if(cin >> tmp)
		cout << "ERROR: extra data at end of file\n";
	
	return 0;
}
