#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

/*
 * For each data set, we 

/* Main body of program */
void process(void)
{
    int data_num, data_idx;

    /* Read how many data sets to process */
    cin >> data_num;
    
    /* Process each data set separately */
    for(data_idx = 0; data_idx < data_num; data_idx++) {
        int op_num, op_idx, str_num, str_idx;

        vector<string> data;
        map<int, string> inserts;
        map<int, bool> deletes;
    
        /* Read how many strings to read and queue operations to process */
        cin >> str_num >> op_num;

        /* Read in all strings */
        for(str_idx = 0; str_idx < str_num; str_idx++) {
            string s;
            
            cin >> s;
            data.push_back(s);
        }

        /* Read all queue operations */
        for(op_idx = 0; op_idx < op_num; op_idx++) {
            int src, dst;

            /* Problem queue locations are 1 based but vector<> is 0 based */
            cin >> src >> dst;
            src--;
            dst--;

            /* Queue position "src" will be moved from its original position */
            deletes[src] = true;

            /* Queue position "dst" will contain item originally at "src" */
            inserts[dst] = data[src];
        }        

        /* Print out the resulting queue as it would appear */
        int src, dst;
        for(src = 0, dst = 0; dst < str_num; dst++) {
                            
            if(inserts[dst] != "") {
                cout << inserts[dst] << " ";
            }

            else {            
            
                while(deletes[src]) {
                    src++;
                }
                
                cout << data[src] << " ";
                src++;
            }
        }

        cout << endl;
    }
}

/* Run program and print out any exceptions that occur */
int main(void)
{
    /* Throw exceptions on EOF or failed data extraction in >> operator */
    cin.exceptions(ios::eofbit | ios::failbit);

    /* Run main body of code */
    try {
        process();
    }
    
    /* Catch any internally generated exceptions */
    catch(char const *e) {
        cerr << "Exception: " << e << endl;
    }
    
    /* Catch unexpected EOF or bad input data */
    catch(ios::failure const &e) {
        cerr << "Unexpected EOF or data type mismatch on input" << endl;
    }

    return 0;
}