import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int[] minimumZooNumbers(int m, int n, char[] t, int[] s, int[] d) { // Return a list of length n consisting of the answers List> ECstart; List> DMstart; return null; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int cases = in.nextInt(); for(int a0 = 0; a0 < cases; a0++){ int m = in.nextInt();//10 int n = in.nextInt();//3 char[] t = new char[n]; for(int t_i = 0; t_i < n; t_i++){ t[t_i] = in.next().charAt(0);// E D C } int[] s = new int[n]; for(int s_i = 0; s_i < n; s_i++){ s[s_i] = in.nextInt(); //SOURCE } int[] d = new int[n]; for(int d_i = 0; d_i < n; d_i++){ d[d_i] = in.nextInt(); //DESTINATION } //sort t[] s[] d[] based on d (ascending) for (int nn = 0; nn < n; nn++) { for (int mm = 0; mm < n - 1 - nn; mm++) { if (d[mm] > d[mm + 1]) { char swapChar = t[mm]; t[mm] = t[mm + 1]; t[mm + 1] = swapChar; int swapInt = s[mm]; s[mm] = s[mm + 1]; s[mm + 1] = swapInt; int swapInt2 = d[mm]; d[mm] = d[mm + 1]; d[mm + 1] = swapInt2; } } } //sort t[] s[] d[] based on s (ascending) for (int nn = 0; nn < n; nn++) { for (int mm = 0; mm < n - 1 - nn; mm++) { if (s[mm] > s[mm + 1] && d[mm] == d[mm + 1]) { char swapChar = t[mm]; t[mm] = t[mm + 1]; t[mm + 1] = swapChar; int swapInt = s[mm]; s[mm] = s[mm + 1]; s[mm + 1] = swapInt; int swapInt2 = d[mm]; d[mm] = d[mm + 1]; d[mm + 1] = swapInt2; } } } //test print for(int idx=0;idx { public E First; public F Second; public G Third; }