🏡 index : github.com/captn3m0/codechef.git

---
category_name: easy
problem_code: HDELIVER
problem_name: 'Home Delivery'
languages_supported:
    - ADA
    - ASM
    - BASH
    - BF
    - C
    - 'C99 strict'
    - CAML
    - CLOJ
    - CLPS
    - 'CPP 4.3.2'
    - 'CPP 4.9.2'
    - CPP14
    - CS2
    - D
    - ERL
    - FORT
    - FS
    - GO
    - HASK
    - ICK
    - ICON
    - JAVA
    - JS
    - 'LISP clisp'
    - 'LISP sbcl'
    - LUA
    - NEM
    - NICE
    - NODEJS
    - 'PAS fpc'
    - 'PAS gpc'
    - PERL
    - PERL6
    - PHP
    - PIKE
    - PRLG
    - PYTH
    - 'PYTH 3.4'
    - RUBY
    - SCALA
    - 'SCM guile'
    - 'SCM qobi'
    - ST
    - TCL
    - TEXT
    - WSPC
max_timelimit: '3'
source_sizelimit: '50000'
problem_author: yellow_agony
problem_tester: anton_lunyov
date_added: 18-01-2012
tags:
    - easy
    - march12
    - yellow_agony
editorial_url: 'http://discuss.codechef.com/problems/HDELIVER'
time:
    view_start_date: 1331461658
    submit_start_date: 1331461658
    visible_start_date: 1331458200
    end_date: 1735669800
    current: 1493558152
layout: problem
---
All submissions for this problem are available.Chef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries. For this he has came up with an idea - he will group together all those orders which have to be delivered in nearby areas. In particular, he has identified certain bidirectional roads which he calls as fast roads. They are short and usually traffic free, so the fast travel is possible along these roads. His plan is that he will send orders to locations **A** and **B** together if and only if it is possible to travel between **A** and **B** using only fast roads. Your task is, given the configuration of fast roads, identify which orders are to be sent together.

### Input

First line of input contains an integer **T**, the number of test cases. Then **T** test cases follow. First line of each test case contains two space separated integers **N** and **M**, denoting number of locations and the number of fast roads. Then **M** lines follow each containing two space separated integers **A** and **B**, denoting that there is a fast road between locations **A** and **B**. Assume that locations are indexed by numbers from 0 to **N-1**. 

Next line contains an integer **Q** denoting the number of queries. Each of the next **Q** lines contain two integers **X** and **Y**. For each query you have to find out if orders meant for locations **X** and **Y** are to be sent together or not. 

Note that there might be multiple fast roads between same pair of locations, also there might be a fast road that links a location to itself.

### Output

For each test case print **Q** lines - one for each query. Output "YO" if the orders are to be delivered together and "NO" otherwise (quotes for clarity).

### Constraints

<pre>
1  <b>T</b>  100
1  <b>N</b>  100
1  <b>M</b>  1000
0  <b>A, B, X, Y</b>  <b>N-1</b>
1  <b>Q</b>  3000
</pre>### Example

<pre>
<b>Input:</b>
1
4 2
0 1
1 2
3
0 2
0 3
2 1

<b>Output:</b>
YO
NO
YO
</pre>### Warning!

**There are large input and output files in this problem. Make sure you use fast enough I/O methods.**