/*
	[NWERC'10] RANKINGS
	Jeroen Bransen
	O(N^2): Build a graph from the input and run a topological sort on it
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define MAXN 500

bool before[MAXN+1][MAXN+1];
bool incall[MAXN+1];
bool done[MAXN+1];
int ranks[MAXN];
int order[MAXN];
int n, norder;

bool dfs(int i) {
	int j;
	if(incall[i])
		return true;
	if(done[i])
		return false;
	incall[i] = true;
	done[i] = true;
	for(j = 1; j <= n; j++)
		if(before[i][j])
			if(dfs(j))
				return true;
	incall[i] = false;
	order[norder++] = i;
	return false;
}

void testcase() {
	int i, j, m, a, b;
	scanf("%d\n", &n);
	memset(before, false, sizeof(before));
	for(i = 0; i < n; i++) {
		scanf("%d", &ranks[i]);
		for(j = 0; j < i; j++)
			before[ranks[i]][ranks[j]] = true;
	}
	scanf("%d\n", &m);
	for(i = 0; i < m; i++) {
		scanf("%d %d\n", &a, &b);
		before[a][b] ^= true;
		before[b][a] ^= true;
	}
	memset(order, 0, sizeof(order));
	memset(incall, false, sizeof(incall));
	memset(done, false, sizeof(done));
	norder = 0;
	for(i = 1; i <= n; i++) {
		if(!done[i] && dfs(i)) {
			printf("IMPOSSIBLE\n");
			return;
		}
	}
	for(i = 0; i < n; i++) {
		if(i) putchar(' ');
		printf("%d", order[i]);
	}
	putchar('\n');
}

int main() {
	int t;
	scanf("%d\n", &t);
	while(t--) testcase();
	return 0;
}
