#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdint>
#include <utility>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL); 
	int t;
	cin >> t;
	int n;
	int m;
	int s;
	for (int i = 0; i < t; i++)
	{
		cin >> n >> m >> s;
		vector<pair<int, int>> v(s);
		vector<pair<int, int>> grane(m);
		for (int j = 0; j < s; j++)
		{
			int a; cin >> a;
			pair<int, int> p(a, 0);
			v[j] = p;
		}
		bool pool = true;
		for (int k = 0; k < m; k++)
		{
			int x, y;
			cin >> x >> y;
			pair<int, int> pom(x, y);
			grane[k] = pom;
			for (int l = 0; l < s; l++)
			{
				if (pool = false) break;
				if (v[l].first == x) v[l].second++;
				if (v[l].first == y) v[l].second++;
				if (v[l].second > 1)
				{
					pool = false; break;
				}
			}
		}
		if (pool = false) cout << -1 << endl;
		else
		{
			for (int k = 0; k < m; k++)
			{
				cout << grane[k].first << grane[k].second << endl;
			}
		}
	}
	
}