This page is still under construction.

Parts of this page are still being built. What you see may change.

Travel

Time limit1sMemory limit128 MB

Summary
Decide whether a simple cycle exists that uses two required roads and avoids all toll roads.
Level

Medium7 of 10

Topics
Graph, DFS
Solved
No attempts yet

Problem

Kim works at a travel agency. A customer from abroad asked him to plan a trip. The customer insists on driving along two famous roads lined with flowers in full bloom. The trip works like this: the customer flies into some city, rents a car, drives a route, and returns to the very city where the trip started. The customer refuses to pass through the same city twice or drive the same road twice, and refuses to drive on any toll road. The number of cities on the route does not matter. Write a program that decides whether such a plan is possible.

For example, consider the maps in Figure 1. A circle is a city, and a line between two circles is a road joining them. The two bold lines are the famous roads the customer wants to drive, and the dotted line is a toll road.

Figure 1

In Figure 1(a), possible plans include 1 → 2 → 4 → 5 → 3 → 1 and 2 → 3 → 5 → 4 → 2. In Figure 1(b), no plan meets the requirements.

Given a map together with the two famous roads and the toll roads, decide whether a valid travel plan exists.

Input

The first line contains the number of test cases TT. Each test case has the following form.

The first line contains two integers NN and MM (5≤N≤10005 \le N \le 1000): the number of cities and the number of roads. Each of the next MM lines contains two integers, the two cities joined by a road. The next two lines each contain one road that the customer wants to drive (the two famous roads). The next line contains an integer FF (0≤F≤M0 \le F \le M), the number of toll roads, and each of the following FF lines contains one toll road.

Cities are labeled from 11 to NN. There is at most one road between any two cities. Neither of the two famous roads is a toll road.

Output

For each test case, print a single line containing YES if a valid travel plan exists, and NO otherwise.

Examples2

  1. Example 1

    Input
    3
    6 8
    2 1
    1 3
    4 5
    2 4
    5 3
    2 3
    3 6
    5 6
    3 5
    2 4
    1
    6 5
    6 8
    2 1
    1 3
    4 5
    2 4
    5 3
    2 3
    3 6
    5 6
    2 3
    3 5
    1
    4 2
    5 4
    1 2
    2 3
    3 4
    4 5
    1 2
    4 5
    2
    2 3
    3 4
    
    Expected output
    YES
    NO
    NO
    
  2. Example 2

    Input
    1
    5 5
    1 2
    2 3
    3 4
    4 5
    5 1
    1 2
    3 4
    0
    
    Expected output
    YES