// COCI-2008-3
// 2008.12.13

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

#define VI vector<int>
#define int64 long long
#define VVI vector <vector<int> >

#define SZ(a) a.size()
#define MP make_pair
#define PII pair<int, int>
#define PB push_back
#define ALL(a) a.begin(), a.end()
#define CLA(a) memset(a, 0, sizeof(a))
#define FOR(i,n) for (int i = 0; i < int(n); i++)
#define FORE(i,a, b) for (int i = a; i <= b; i++)
#define FORR(i,n) for (int i = n - 1; i >=0; i--)
#define REP(n) for (int _foo = n - 1; _foo >= 0; _foo--)

#define INF 1000000000

int ri() {int t; scanf("%d", &t); return t;}
void rs(char *s) {scanf("%s", s);}
void pi(int n){printf("%d\n", n);}

int p, f[30000], n, k, res;

char rr[64][30000], fr[64];

int cnt[32];

inline void sset(int x0, int xn, int y, int val)
{
	val = 32 - val + 'A';

	if (f[y])
	{
		FORE(x, x0, xn)
			rr[f[y]-1][x] = val;
	}
	FOR(i, res)
		if (fr[i] >= x0 && fr[i] <= xn)
			rr[i][y] = val;
}

char s[100];

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
	priority_queue <int> diag;
	priority_queue <PII> a;
	
	gets(s); sscanf(s, "%d %d", &n, &k); //n = ri(); k = ri();
	FOR(i,k)
	{
		char c; int cc; gets(s); sscanf(s, "%c %d", &c, &cc);
		c -= 'A';
		if (cc % 2)
		{
			cc--;
			diag.push(32-(int)c);
		}
		//cnt[cc]++;
		a.push(MP(32-(int)c, cc));
	}

	res = ri();
	FOR(i, res) fr[i] = ri() - 1;
	FOR(i, res) f[fr[i]] = i + 1;

	if (diag.size() > n)
	{
		puts("IMPOSSIBLE"); return 0;
	}

	for (int col = 0; col < n; col++)
	{
		int sz = diag.size();
		int c = 0;
		if (sz < n - col && (diag.empty() || diag.top() < a.top().first))
		{
			PII t = a.top(); a.pop();
			c = t.first;
			t.second -= 2;
			if (t.second)
				a.push(t);
			diag.push(c);
		}
		else
		{
			c = diag.top(); diag.pop();
		}
		sset(col, col, col, c);
		PII t(0,0);
		int row = col + 1;
		//for (int row = col + 1; row < n; row++)
		while (row < n)
		{
			while (!t.second) t = a.top(), a.pop();
			int left = n - row;
			int can = min(t.second / 2, left);
			t.second -= 2 * can;
			//t.second -= 2;
			sset(row, row + can - 1, col, t.first);
			row += can;
		}
		if (t.second)
			a.push(t);
	}

	FOR(row, n)
	{
		//FOR(col, n) if (f[col])
			//putchar(r[row][col]);
		FOR(i, res)
			putchar(rr[i][row]);
		putchar('\n');
	}
}
 