// Author: Adrian Kuegel
// Date: November 4th, 2010
// Algorithm: straight-forward
// Complexity: O(n^2)

import java.io.*;
import java.util.*;

public class adrian {
	public static void main(String [] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int tc = Integer.parseInt(in.readLine());
		while(tc-- > 0) {
			int n = Integer.parseInt(in.readLine());
			boolean [][] better = new boolean[n][n];
			int [] t = new int[n];
			StringTokenizer strtok = new StringTokenizer(in.readLine());
			for (int i=0; i<n; ++i) {
				t[i] = Integer.parseInt(strtok.nextToken())-1;
				for (int j=0; j<i; ++j)
					better[t[j]][t[i]] = true;
			}
			int m = Integer.parseInt(in.readLine());
			for (int i=0; i<m; ++i) {
				strtok = new StringTokenizer(in.readLine());
				int a = Integer.parseInt(strtok.nextToken())-1;
				int b = Integer.parseInt(strtok.nextToken())-1;
				boolean temp = better[a][b];
				better[a][b] = better[b][a];
				better[b][a] = temp;
			}
			int [] pos = new int[n];
			boolean valid = true;
			for (int i=0; i<n; ++i) {
				int cnt = 0;
				for (int j=0; j<n; ++j)
					if (better[j][i])
						++cnt;
				if (pos[cnt] != 0)
					valid = false;
				pos[cnt] = i + 1;
			}
			if (valid)
				for (int i=0; i<n; ++i)
					System.out.print(pos[i]+(i<n-1?" ":"\n"));
			else
				System.out.println("IMPOSSIBLE");
		}
	}
}
