Chef and Strings

Read problem statements in Mandarin Chinese.

Having already mastered cooking, Chef has now decided to learn how to play the guitar. Often while trying to play a song, Chef has to skip several strings to reach the string he has to pluck. Eg. he may have to pluck the  string and then the  string. This is easy in guitars with only  strings; However, Chef is playing a guitar with  strings. In order to simplify his task, Chef wants you to write a program that will tell him the total number of strings he has to skip while playing his favourite song.

Chef and Strings

This is how guitar strings are numbered (In ascending order from right to left). Eg. to switch from string  to , Chef would have to skip  strings . 

Input:

  • First line will contain , number of testcases. Then the testcases follow. 
  • The first line of each test case contains , the number of times Chef has to pluck a string
  • The second line of each test case contains  space separated integers - , , …, , where  is the number of the  string Chef has to pluck.

Output:

For each testcase, output the total number of strings Chef has to skip over while playing his favourite song. 

Constraints

  • For each valid , 

Subtasks

  • 30 points : for each valid , 
  • 70 points : No additional constraints

Sample Input:

2
6
1 6 11 6 10 11
4
1 3 5 7

Sample Output:

15
3

Explanation:

Test Case 

  • Chef skips  strings  to move from  to 
  • Chef skips  strings  to move from  to 
  • Chef skips  strings  to move from  to 
  • Chef skips  strings  to move from  to 
  • Chef skips  strings to move from  to 

Therefore, the answer is 

Test Case 

  • Chef skips  string to move from  to 
  • Chef skips  string to move from  to 
  • Chef skips  string to move from  to 

Therefore, the answer is 

Comments

Popular posts from this blog

Access and modify all the resources of our Wiki.js using WikiJS API

MySQL Multi Source Master Slave Replication using GTID

How to pass parameters in webhook?