They call him the Seal, not because he swims, but because every case he touches gets closed. Stamped shut. Sealed. A few miles up the coast from Aqua Badran sprawls Aquarbour, a city so overcrowded that three people can witness a murder and all swear they were looking the other way. Last Tuesday, someone walked into the Aquarbour National Archive and walked out with the Ledger, a book the city's elite would very much prefer remained unread. The Seal took the case for one shawarma sandwich and a cup of Al Ameed coffee. His only lead: the thief left behind two coded sequences, scratched into the marble floor in two parallel rows.
The first line contains $$$t$$$ ($$$1 \le t \le 10^4$$$), the number of cases on the Seal's desk. For each test case:
For each test case, print one integer, the minimum effort the Seal must spend before the marble gives up its name.
3 2 1 1 3 1 4 2 3 1 3 5 3 1 2 4 6 4 4 3 7 5 3 1 2 6 4 8
0 2 7
Case 1. The marble is already talking ($$$3 \lt 4$$$). The Seal lights a cigarette and writes the name down. Cost: $$$0$$$. Case 2. Granite is unforgiving ($$$c_b = 3$$$). The Seal works only the limestone row, sliding $$$1$$$ to the front of row $$$a$$$ in two swaps: $$$[1, 5, 3]$$$, which already reads smaller than $$$[2, 4, 6]$$$. Cost: $$$2 \cdot 1 = 2$$$. Case 3. Now both chisels come out. One swap on row $$$a$$$ (cost $$$4$$$) brings $$$5$$$ to the front: $$$[5, 7, 3, 1]$$$. One swap on row $$$b$$$ (cost $$$3$$$) brings $$$6$$$ to the front: $$$[6, 2, 4, 8]$$$. Since $$$5 \lt 6$$$, the marble confesses. Total cost: $$$4 + 3 = 7$$$.