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

public class brackets_as implements Runnable {
    public void solve() throws IOException {
        Scanner in = new Scanner(new File("brackets.in"));
        PrintWriter out = new PrintWriter("brackets.out");

        int testn = in.nextInt();

        for (int test = 0; test < testn; test++) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] order = new int[2 * k];
            int[] indp = new int[k + 1];
            int[] indpop = new int[k + 1];
            int[] indn = new int[k + 1];
            int[] orderop = new int[k];
            int[] nextop = new int[k + 1];
            int z = 0;
            for (int i = 0; i < 2 * k; i++) {
                order[i] = in.nextInt();
                if (order[i] > 0) {
                    indp[order[i]] = i;
                    orderop[z++] = order[i];
                    indpop[order[i]] = z - 1;
                }
                if (order[i] < 0) {
                    indn[-order[i]] = i;
                }
            }

            int theNextOp = 0;
            for (int i = 2 * k - 1; i >= 0; i--) {
                if (order[i] > 0) {
                    theNextOp = order[i];
                } else {
                    nextop[-order[i]] = theNextOp;
                }
            }

            int[] seq = new int[2 * n];
            for (int i = 0; i < 2 * n; i++) {
                seq[i] = in.nextInt();
            }

            int[] lastOp = new int[2 * n];
            int[] stack = new int[n];
            int sp = 0;
            for (int i = 0; i < 2 * n; i++) {
                if (seq[i] > 0) {
                    if (sp > 0) {
                        lastOp[i] = stack[sp - 1];
                    }
                    stack[sp++] = seq[i];
                } else {
                    sp--;
                }
            }

            int l = 0;
            int level = 0;
            for (int i = 2 * n - 1; i >= 0; i--) {
                if (seq[i] > 0) {
                    level--;
                    if (indpop[seq[i]] == k - 1 && (lastOp[i] == 0 || indn[lastOp[i]] < indp[seq[i]])) {
                        continue;
                    }
                    if (indpop[seq[i]] == k - 1 || (lastOp[i] != 0 && indn[lastOp[i]] > indp[seq[i]] && indn[lastOp[i]] < indp[orderop[indpop[seq[i]] + 1]])) {
                        seq[i] = -lastOp[i];
                        l = i + 1;
                        break;
                    } else {
                        seq[i] = orderop[indpop[seq[i]] + 1];
                        l = i + 1;
                        break;
                    }
                } else {
                    level++;
                    if (2 * n - 1 - i < level + 1 || nextop[-seq[i]] == 0) {
                        continue;
                    }
                    seq[i] = nextop[-seq[i]];
                    l = i + 1;
                    break;
                }
            }

            sp = 0;
            for (int i = 0; i < l; i++) {
                if (seq[i] > 0) {
                    stack[sp++] = seq[i];
                } else {
                    sp--;
                }
            }

            for (int i = l; i < 2 * n; i++) {
                if (sp == 2 * n - i || (sp > 0 && indn[stack[sp - 1]] < indp[orderop[0]])) {
                    seq[i] = -stack[--sp];
                } else {
                    seq[i] = orderop[0];
                    stack[sp++] = seq[i];
                }
            }


            for (int i = 0; i < 2 * n; i++) {
                out.print(seq[i]);
                if (i < 2 * n) {
                    out.print(" ");
                }
            }
            out.println();
        }

        in.close();
        out.close();
    }

    public void run() {
        try {
            solve();
        } catch (IOException e) {
        }
    }

    public static void main(String[] arg) {
        new Thread(new brackets_as()).start();
    }
}