#include <bits/stdc++.h>
using namespace std;

char word[10005];
int main(){
    ios::sync_with_stdio(0);
    int t; cin>>t;
    while (t--){
        int n,q; cin>>n>>q;
        for (int i=1;i<=n;i++) word[i]='_';
        bool good=true;
        while (q--){
            int k; string s; cin>>k>>s;
            int p=k;
            for (int i=0;i<s.size();i++){
                if (s[i]!='*'){
                    if (word[p]=='_') word[p]=s[i];
                    if (word[p]!=s[i]) good=false;
                    p++;
                }
                else{
                    p+=n-k+1-(s.size()-1); 
                }
            }
        }
        for (int i=1;i<=n;i++) if (word[i]=='_') good=false;
        if (good){
            for (int i=1;i<=n;i++) cout<<word[i]; cout<<endl;
        }
        else cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}