```
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <string.h>

#include <time.h>
#include <random>
#include <iomanip>
using namespace std;

#define ll long long
#define N 10005

ll solution[N];
string strs[N];
ll lens[N];

void solve() {
ll l, s;
cin >> l >> s;

for (ll i = 0; i < N; i++)
solution[i] = -1;

for (ll i = 0; i < s; i++) {
cin >> lens[i];
cin >> strs[i];
}

for (ll i =0 ; i < s; i++) {
string str = strs[i];
ll len = lens[i];

ll curIndex = len-1;
for (ll j = 0; j < str.size(); j++) {
if (str[j] != '*') {
if (solution[curIndex] != -1 && solution[curIndex] != str[j]) {
cout << "IMPOSSIBLE" << endl;
return;
}
solution[curIndex] = str[j];
curIndex++;
}
else {
ll totalLen = l-len+1;
ll starLen = totalLen - (str.size()-1);
curIndex += starLen;
}
}
}

for (ll i = 0; i < l; i++) {
if (solution[i] == -1) {
cout << "IMPOSSIBLE" << endl;
return;
}
}
for (ll i = 0; i < l; i++) {
cout << (char)(solution[i]);
}
cout << endl;
}

int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
ll t;
cin >> t;
for (ll i = 0; i < t; i++) {
solve();
}
}```