#include <iostream>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int ncase; cin >> ncase;
	for (int csnum = 1; csnum <= ncase; csnum++) {
		int len, nums; cin >> len >> nums;
		string res(len, '-');
		bool good = true;
		for (int i = 0; i < nums; i++) {
			int p; string s; cin >> p >> s;
			int j = 0;
			while (j < s.length() && s[j] != '*') {
				int jj = p-1+j;
				if (res[jj] != '-' && res[jj] != s[j]) {
					good = false;
				} else {
					res[jj] = s[j];
				}
				j++;
			}
			j = s.length()-1;
			while (j >= 0 && s[j] != '*') {
				int jj = res.length() - (s.length() - j);
				if (res[jj] != '-' && res[jj] != s[j]) {
					good = false;
				} else {
					res[jj] = s[j];
				}
				j--;
			}
		}
		if (good) {
			for (int i = 0; i < len; i++) {
				if (res[i] == '-') {
					good = false;
					break;
				}
			}
		}
		if (good) {
			cout << res << endl;
		} else {
			cout << "IMPOSSIBLE" << endl;
		}
	}
}