#include <iostream>
#include <cstdio>
using namespace std;

const int MAXDICE = 20;
const int MAXFACES = 20;
const int MAXFACEVAL = 50;
const int MAXDESIRED = 10;

int currDie[MAXFACES];
int vals[MAXDICE*MAXFACEVAL][2];
struct target {
	int val;
	long num;
} desired[MAXDESIRED];

bool checkDesired(int n)
{
	for(int i=0; i<n; i++) {
		if (desired[i].num != 0)
			return false;
	}
	return true;
}

bool findDie(int numFaces, int numVals, int face, int startVal, int min)
{
	if (face == numFaces) {
		return checkDesired(numVals);
	}
	int val = startVal;
	currDie[face] = val;
	while (true) {
		int i;
		bool ok = true;
		for(i=0; i<numVals; i++) {
			if (desired[i].val - val > 0) {
				desired[i].num -= vals[desired[i].val-val][0];
				if (desired[i].num < 0)
					ok = false;
			}
		}
		if (ok) {
			if (findDie(numFaces, numVals, face+1, val, min))
				return true;
		}

		for(i=0; i<numVals; i++) {
			if (desired[i].val - val > 0) {
				desired[i].num += vals[desired[i].val-val][0];
			}
		}
		for(i=0; i<numVals; i++) {
			if (min+val >= desired[i].val && desired[i].num != 0)
				return false;
		}
		if (++val > MAXFACEVAL)
			return false;
		currDie[face] = val;
	}
	return false;		// should never happen
}


int main()
{
	int n;
	cin >> n;
	while (n != 0) {
		for(int j=0; j<MAXDICE*MAXFACEVAL; j++)
			vals[j][0] = 0;
		vals[0][0] = 1;
		double totalFaces = 1;
		for(int i=0; i<n; i++) {
			int f;
			cin >> f;
			totalFaces *= f;
			for(int j=0; j<MAXDICE*MAXFACEVAL; j++) {
				vals[j][1] = vals[j][0];
				vals[j][0] = 0;
			}
			for(int k=0; k<f; k++) {
				int val;
				cin >> val;
				for(int j=0; j<MAXDICE*MAXFACEVAL-val; j++) {
					if (vals[j][1] > 0)
						vals[j+val][0] += vals[j][1];
				}
			}
		}

		int r, m;
		cin >> r >> m;
		for(int k=0; k<m; k++) {
			cin >> desired[k].val >> desired[k].num;
		}
		int min=0;
		while (vals[min][0] == 0)
			min++;
		if (findDie(r, m, 0, 1, min)) {
			cout << "Final die face values are";
			for(int k=0; k<r; k++) {
				cout << " " << currDie[k];
			}
		}
		else
			cout << "Impossible";
		cout << endl;

		cin >> n;
	}
return 0;
}
