// Author: Adrian Kuegel
// Date: September 8th, 2010
// Algorithm: straight-forward
// Complexity: O(n)

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

#define MAXN 500
#define MAXM 25000
// uncomment if no asserts should be used
//#define NDEBUG
#include <assert.h>

#ifndef NDEBUG
#include <set>
#include <utility>
typedef pair<int, int> PII;
#endif

int cnt_better[MAXN], pos[MAXN];

int main() {
	int tc;
	scanf("%d", &tc);
	assert(tc >= 1 && tc <= 100);
	while(tc--) {
		int n, t;
		scanf("%d", &n);
		assert(n >= 2 && n <= MAXN);
		memset(pos, -1, sizeof(int) * n);
		for (int i=0; i<n; ++i) {
			scanf("%d", &t);
			--t;
			assert(t >= 0 && t < n && pos[t] == -1);
			cnt_better[t] = pos[t] = i;
		}
		int m, a, b;
		scanf("%d", &m);
		assert(m <= MAXM);
#ifndef NDEBUG
		set<PII> used;
#endif
		for (int i=0; i<m; ++i) {
			scanf("%d %d", &a, &b);
			--a;
			--b;
			assert(a >= 0 && a < b && b < n);
			if (pos[a] > pos[b])
				swap(a, b);
#ifndef NDEBUG
			assert(used.insert(PII(a, b)).second);
#endif
			++cnt_better[a];
			--cnt_better[b];
		}
		memset(pos, -1, sizeof(int) * n);
		bool valid = true;
		for (int i=0; i<n; ++i) {
			if (pos[cnt_better[i]] != -1)
				valid = false;
			pos[cnt_better[i]] = i;
		}
		if (valid) {
			for (int i=0; i<n; ++i) {
				if (i) printf(" ");
				printf("%d", pos[i]+1);
			}
			puts("");
		}
		else
			puts("IMPOSSIBLE");
	}
	return 0;
}
