The Structure of remote is :
Everytime a user wants to switch to a channel, he'll first have to press the digits of the channel (i.e the numbers) then press the "fire" button. Also he may use +/- buttons to navigate through the channels.
+/- and fire buttons are costly, everytime these buttons are pressed a cost of 1 unit is added. The digit buttons of the remote are not working properly, only some of the digit buttons are working. The channel numbers of the TV are from 0 to 1000000 and digits in the remote are 0 to 9.
You will be given which digit buttons are working properly. Q queries will be asked, each of which has two channel numbers first one is the current channel number other one is the destination channel number. For each query print the cost of switching the channel.
PS: The + and - button won't be working at channel number 1000000 and 0 respectively.
- The first line of the input contains an integer T denoting the number of test cases . The description of T testcases follow.
- First line of each test case contains 10 space seperated integers denoting whether i th digit button is working or not. If ith element is 1 means it is working properly else if it’s 0 it’s not working.
- Second line of each test case contains a single integer Q denoting number of queries.
- Next Q line contains two space seperated integer C D denoting Current channel number and destination channel number.
For each Query print the cost of switching channel.
- 1 ≤ T ≤ 20
- 1 ≤ Q ≤ 10000
- 0 ≤ C ≤ 1000000
- 0 ≤ D ≤ 1000000
0 1 1 0 1 1 0 1 0 1
from 0 he will go direct to 111.
from 1->124 then 124->123, cost will be 2.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions