Problem: Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective story books. 

You are not informed on what crime was committed, when and where the corpse was found and other details. We only know that the crime was committed in a house that has n rooms and m doors between the pairs of rooms. The house residents are very suspicious, that's why all the doors can be locked with keys and all the keys are different. According to the provided evidence on Thursday night all the doors in the house were locked, and it is known in what rooms were the residents, and what kind of keys had any one of them. The same is known for the Friday night, when all the doors were also locked. On Friday it was raining heavily, that's why nobody left the house and nobody entered it. During the day the house residents could

  * open and close doors to the neighboring rooms using the keys at their disposal (every door can be opened and closed from each side); 
  * move freely from a room to a room if a corresponding door is open; 
  * give keys to one another, being in one room. 



"Little grey matter" of Hercule Poirot are not capable of coping with such amount of information. Find out if the positions of people and keys on the Thursday night could result in the positions on Friday night, otherwise somebody among the witnesses is surely lying.

Input

The first line contains three preset integers n, m и k (1 ≤ n, m, k ≤ 1000) — the number of rooms, the number of doors and the number of house residents respectively. The next m lines contain pairs of room numbers which join the doors. The rooms are numbered with integers from 1 to n. There cannot be more that one door between the pair of rooms. No door connects a room with itself. The next k lines describe the residents' position on the first night. Every line contains a resident's name (a non-empty line consisting of no more than 10 Latin letters), then after a space follows the room number, then, after a space — the number of keys the resident has. Then follow written space-separated numbers of the doors that can be unlocked by these keys. The doors are numbered with integers from 1 to m in the order in which they are described in the input data. All the residents have different names, uppercase and lowercase letters considered to be different. Every m keys occurs exactly once in the description. Multiple people may be present in one room, some rooms may be empty. The next k lines describe the position of the residents on the second night in the very same format. It is guaranteed that in the second night's description the residents' names remain the same and every m keys occurs exactly once.

Output

Print "YES" (without quotes) if the second arrangement can result from the first one, otherwise, print "NO".

Examples

Input

2 1 2
1 2
Dmitry 1 1 1
Natalia 2 0
Natalia 1 1 1
Dmitry 2 0


Output

YES


Input

4 4 3
1 3
1 2
2 3
3 4
Artem 1 1 4
Dmitry 1 1 2
Edvard 4 2 1 3
Artem 2 0
Dmitry 1 0
Edvard 4 4 1 2 3 4


Output

NO

Solution (in JAVA):

Solution:
//package round43;

import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class F {
	Scanner in;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		int m = ni();
		int k = ni();
		int[][] link = new int[m][2];
		for(int i = 0;i < m;i++){
			int f = ni() - 1;
			int t = ni() - 1;
			if(f > t){
				int d = f; f = t;t = d;
			}
			link[i][0] = f;
			link[i][1] = t;
		}
		
		BitSet[] verkey = new BitSet[n]; // [頂点] = 鍵
		for(int i = 0;i < n;i++){
			verkey[i] = new BitSet();
		}
		for(int i = 0;i < m;i++){
			verkey[link[i][0]].set(i);
			verkey[link[i][1]].set(i);
		}
		
		Map<String, Integer> nameInd = new HashMap<String, Integer>();
		int[] ikeys = new int[m]; // [鍵] = 持ち主
		BitSet[] team = new BitSet[n];
		for(int i = 0;i < n;i++)team[i] = new BitSet();
		int[] posteam = new int[n];
		Resident[] r = new Resident[k];
		BitSet start = new BitSet();
		for(int i = 0;i < k;i++){
			Resident re = new Resident();
			re.name = in.next();
			re.pos = ni() - 1;
			int u = ni();
			int[] keys = new int[u];
			for(int j = 0;j < u;j++){
				keys[j] = ni() - 1;
				ikeys[keys[j]] = i;
			}
			re.keys = keys;
			start.set(re.pos);
			r[i] = re;
			
			nameInd.put(re.name, i);
		}
		
		simulate(team, posteam, r, start, k, link, n, ikeys, verkey);
		
		int[] ikeys2 = new int[m]; // [鍵] = 持ち主
		BitSet[] team2 = new BitSet[n];
		for(int i = 0;i < n;i++)team2[i] = new BitSet();
		int[] posteam2 = new int[n];
		Resident[] r2 = new Resident[k];
		BitSet start2 = new BitSet();
		for(int i = 0;i < k;i++){
			Resident re = new Resident();
			re.name = in.next();
			re.pos = ni() - 1;
			int u = ni();
			int[] keys = new int[u];
			for(int j = 0;j < u;j++){
				keys[j] = ni() - 1;
				ikeys2[keys[j]] = i;
			}
			re.keys = keys;
			start2.set(re.pos);
			r2[i] = re;
		}
		
		simulate(team2, posteam2, r2, start2, k, link, n, ikeys2, verkey);
		
		for(int i = 0;i < k;i++){
			Resident re2 = r2[i];
			int ind = nameInd.get(re2.name);
			Resident re = r[ind];
			if(!(posteam2[re.pos] == posteam2[re2.pos] && posteam[re.pos] == posteam[re2.pos])){
				out.println("NO");
				return;
			}
			int te2 = posteam2[re2.pos];
			int te = posteam[re.pos];
			
			{
				BitSet mkey = new BitSet();
				for(int xkey : re2.keys){
					mkey.set(xkey);
				}
				for(int j = team[te].nextSetBit(0);j != -1;j = team[te].nextSetBit(j+1)){
					for(int key : r[j].keys){
						mkey.clear(key);
					}
				}
				if(!mkey.isEmpty()){
					out.println("NO");
					return;
				}
			}
			
			{
				BitSet mkey = new BitSet();
				for(int xkey : re.keys){
					mkey.set(xkey);
				}
				for(int j = team2[te2].nextSetBit(0);j != -1;j = team2[te2].nextSetBit(j+1)){
					for(int key : r2[j].keys){
						mkey.clear(key);
					}
				}
				if(!mkey.isEmpty()){
					out.println("NO");
					return;
				}
			}
		}
		out.println("YES");
	}
	
	public void simulate(BitSet[] team, int[] posteam, Resident[] r, BitSet start, int k, int[][] link, int n, int[] ikeys, BitSet[] verkey)
	{
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		for(int i = start.nextSetBit(0);i != -1;i = start.nextSetBit(i+1)){
			for(int j = verkey[i].nextSetBit(0);j != -1;j = verkey[i].nextSetBit(j+1)){
				q.add(j);
			}
		}
		
		Arrays.fill(posteam, -1);
		for(int i = 0;i < k;i++){
			team[r[i].pos].set(i);
			posteam[r[i].pos] = r[i].pos;
		}
		
		while(!q.isEmpty()){
			int cur = q.pollFirst();
			int v1 = link[cur][0];
			int v2 = link[cur][1];
			int t1 = posteam[v1];
			int t2 = posteam[v2];
			int has = posteam[r[ikeys[cur]].pos];
			if(t1 != has && t2 != has)continue;
			if(t1 >= 0 && t2 >= 0){
				if(t1 == t2)continue;
				// メンバー強奪
				team[t1].or(team[t2]);
				for(int i = 0;i < n;i++){
					if(posteam[i] == t1){
						// t1側の辺を復帰
						for(int j = verkey[i].nextSetBit(0);j != -1;j = verkey[i].nextSetBit(j+1)){
							q.add(j);
						}
					}else if(posteam[i] == t2){
						// t2側の辺を復帰
						for(int j = verkey[i].nextSetBit(0);j != -1;j = verkey[i].nextSetBit(j+1)){
							q.add(j);
						}
						posteam[i] = t1;
					}
				}
			}else if(t1 >= 0){
				for(int j = verkey[v2].nextSetBit(0);j != -1;j = verkey[v2].nextSetBit(j+1)){
					q.add(j);
				}
				posteam[v2] = t1;
			}else if(t2 >= 0){
				for(int j = verkey[v1].nextSetBit(0);j != -1;j = verkey[v1].nextSetBit(j+1)){
					q.add(j);
				}
				posteam[v1] = t2;
			}
		}
	}
	
	class Resident
	{
		public String name;
		public int pos;
		public int[] keys;
	}
	
	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}
	
	
	public static void main(String[] args) throws Exception
	{
		new F().run();
	}
	
	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { System.err.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}