Page Contents

**Helping Army SOLUTIONS ARMYHELP**

**Helping Army SOLUTIONS ARMYHELP**

In armyland there exist a gathering of individuals named ProgrammersArmy who are eager to come up as some assistance for the residents of armyland as due to Coronavirus individuals are not permitted to escape their homes because of which basic things are not provided to them.

So ProgrammersArmy thought of an answer for beating this circumstance, The arrangement was quite basic, they chose to assemble data about the houses in the armyland and the street with which they are associated.

we should signify the all out number of houses in the armyland with N.

Yet, while assembling such data they saw a theme in the separations between each house suppose house An and house B have a separation which is limit of An and B.

Yet, the military came to realize this isn’t adequate data for making their model spread the whole city for conveying things effectively. Subsequently, they chose to accumulate the data that contains the subtleties having the base separation between each house with each other house in the city.

The military chose to some way or another scramble this data with the goal that it won’t be abused. So the encryption calculation which the military followed is as appeared underneath how about we name this calculation as “legend”, where Ans shows the last encoded number and n means our unique number :

Calculation legend: Instate Ans: = 0 On the off chance that whole number n isn’t zero Do bitwise and with (n−1) and allocate the incentive back to n i.e n: = n and ( n – 1 )n and ( n – 1 )

Augmentation Ans by 1 go to stage 2 Else bring Ans back The information that is assembled by a group already is presently scrambled in a specific manner for example the base separation of each house with different houses is passed to our “legend” and the Ans for example returned by the “legend” is done bitwise OR with the subsequent worth got as passing the base of all separations in that chain of houses to “legend”.

Note: here the expression “that chain of houses” in above proclamation relate to a rundown that contains least separation of one house with each other house.

In the wake of scrambling information the military presents this model to head of the military, who questions on the given information which is contained in the model put together by the military and you are needed to answer those inquiries.

Note: The houses are numbered from 1 to N as portrayed previously.

Information:

The primary line of information contains a solitary number T, the absolute no. of experiments. The portrayal of T experiments follows.

The principal line of each experiment comprises of two space-isolated whole numbers N, M signifying the complete number of houses, and the quantity of streets individually.

Next M lines contain two space-isolated A, B indicating that there is a street among An and B.

The following line contains Q indicating the quantity of questions.

The following Q lines contain two space-isolated whole numbers h1, h2 meaning the quantity of the house individually as portrayed previously

Yield:

For each inquiry print a solitary number in the new line signifying the response to the question ( i.e the scrambled separation between house h1 and house h2 ) as contained in the encoded model.

Note : Output of each experiment ought to be imprinted on new line.

Requirements:

1≤T≤103

1≤N≤104

1≤M≤105

1≤A,B,h1,h2≤N

1≤Q≤105

Test Input:

1

6 9

1 2

1 6

2 6

2 3

3 6

3 5

3 4

4 5

5 6

4

1 2

2 5

6 4

3

Test Output:

1

1

2

0

Clarification:

As by building the model and scrambling it with the calculation as portrayed in the inquiry above you will find that the base separation between houses is as per the following :

house 1 and house 2 have a base separation of 1

house 2 and house 5 have a base separation of 1

house 6 and house 4 have a base separation of 2

house 3 and house 3 have a base separation of 0

*March Long Challenge 2021 Solutions*

*March Long Challenge 2021 Solutions*

*An Interesting Sequence ISS SOLUTION**Tree House THOUSES SOLUTION**Valid Paths VPATH SOLUTION**Modular Equation MODEQ SOLUTION**Tic Tac Toe TCTCTOE SOLUTION**Xor Equality XOREQUAL SOLUTION**Golf LKDNGOLF SOLUTION**Solubility SOLBLTY SOLUTION*

*April Long Challenge 2021 Solutions*

*April Long Challenge 2021 Solutions*

*Chef and Dice SDICE Solution**Worthy Matrix KAVGMAT Solution**Binary String MEX MEXSTR Solution**Boolean Game BOOLGAME Solution**Tree Permutations TREEPERM Solution**Destroy the EMP Chip CHAOSEMP Solution**Chef and Pair Flips PAIRFLIP Solution**String Power STRPOW Solution**Brahma and Shiva SHRINES Solution**Water Sort Puzzle (Challenge) WTRSORT Solution**World Record BOLT Solution**Strong Language SSCRIPT Solution**Valid Pair SOCKS1 Solution*

*Codechef Long Challenge Solutions*

*Codechef Long Challenge Solutions*

*February Long Challenge 2021*

*February Long Challenge 2021*

#### 1. Frog Sort Solution Codechef

#### 2. Chef and Meetings Solution Codechef

#### 3. Maximise Function Solution Codechef

#### 4. Highest Divisor Solution Codechef

#### 5. Cut the Cake Challenge Solution Codechef

#### 6. Dream and the Multiverse Solution Codechef

#### 7. Cell Shell Solution Codechef

#### 8. Multiple Games Solution Codechef

#### 9. Another Tree with Number Theory Solution Codechef

#### 10. XOR Sums Solution Codechef

#### 11. Prime Game Solution CodeChef

#### 12. Team Name Solution Codechef

### January Long Challenge 2021

**Chef and Division 3 DIVTHREE SOLUTION Code Chef****Encoded String DECODEIT SOLUTION Code Chef****Point Of Impact BILLRD SOLUTION Code Chef****Fair Elections FAIRELCT SOLUTION Code Chef****Watching CPL WIPL SOLUTION Code Chef****Chef and Ants ANTSCHEF SOLUTION Code Chef****Blackjack BLKJK SOLUTION Code Chef****And-Or Game ORAND SOLUTION Code Chef****Stack-Queue Sort (Challenge) SQSORT SOLUTION Code Chef****Expected Number of SCCs RCTEXSCC SOLUTION Code Chef****Curious Matrix CURMAT SOLUTION Code Chef****Cool Subsets COOLSBST SOLUTION Code Chef****Sequence Creation ARCRT SOLUTION Code Chef****Greedy Students GRDSTD SOLUTION Code Chef**

### November Challenge 2020 SOLUTION CodeChef

- Ada and Dishes SOLUTION ADADISH
- Iron Magnet and Wall SOLUTION FEMA2
- Magical Candy Store SOLUTION CNDYGAME
- Unusual Queries SOLUTION UNSQUERS
- Red-Black Boolean Expression SOLUTION RB2CNF
- Chef and the Combination Lock SOLUTION CHEFSSM
- Scalar Product Tree SOLUTION SCALSUM
- Connect on a Grid (Challenge) SOLUTION CONGRID

### October Lunchtime 2020 CodeChef SOLUTIONS

- AND Plus OR SOLUTION ANDOR
- Chef and Subtree MEXs SOLUTION SUBMEXS
- Chef Likes Good Sequences SOLUTION GSUB
- Cute Chef Gift SOLUTION COPAR
- Chef Is Just Throwing Random Words SOLUTION SSO
- Counting Spaghetti SOLUTION CDSUMS
- Chef and Edge Flipping SOLUTION EFLIP

*RELATED :*

- Top Best Keylogger in Python 3 Make One
*What is Hacking?**Secrets of the Deep Dark Web**CODECHEF September Lunchtime 2020 SOLUTIONS**August Lunchtime 2020 SOLUTIONS*

*Related :*

*A. Shandom Ruffle SOLUTION**B. Pear TreaP SOLUTION**C. Sneetches and Speeches 3 SOLUTION**D. The Grim Treaper SOLUTION**Y. Sneetches and Speeches 1 SOLUTION**Z. Trick or Treap SOLUTION**A. Floor Number SOLUTION CODE FORCES**B. Symmetric Matrix SOLUTION CODE FORCES**C. Increase and Copy SOLUTION CODE FORCES**D. Non-zero Segments SOLUTION CODE FORCES**E. Rock, Paper, Scissors SOLUTION CODE FORCES**F. Number of Subsequences SOLUTION CODE FORCES*

*Related :*

*Chef and Easy Queries SOLUTIONS CHEFEZQ**Covid Run SOLUTIONS CVDRUN OCTOBER CHALLENGE**Positive AND SOLUTIONS POSAND**Replace for X SOLUTIONS REPLESX**Village Road Network SOLUTIONS VILLNET**Random Knapsack SOLUTIONS RANDKNAP**D-Dimensional MST SOLUTIONS DDIMMST**Compress all Subsegments SOLUTIONS SEGCOMPR**Adding Squares SOLUTIONS ADDSQURE**Inversions SOLUTIONS INVSMOD2 OCOTBER CHALLENGE**Rooted Minimum Spanning Tree SOLUTIONS ROOTMST*