Broken Telephone

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Chef is judging a game called "Broken telephone". There are total N players taking part in the game. They are all sitting in a line. In the start of the game, first player is given a secret message written on a sheet of paper. Then they keep sending the message by whispering it to the player sitting immediate right to one and so on until it reaches the last person.
Finally, the message received by the last player is compared with the message said by first player. If these messages aren't equal, there is someone who has misheard the message or whispered it wrongly to the next player. If messages is equal, then the players win and receive a tasty chocolate.
Note that first player receives the message on a sheet of paper, thus he cannot mishear it.
As Chef wants to be sure that every player has fulfilled his/ her role in the game, so he asks everyone to state their received messages after the end of the game. You are given an array A of N integers denoting messages received by each person.
Please help Chef to find the number of players that could mishear the message or whisper it wrongly.
Input
 The first line of the input contains an integer T denoting the number of test cases.
 The first line of each test case contains a single integer N denoting the number of players
 The second line contains N spaceseparated integers A_{1}, A_{2}, ..., A_{N} denoting the messages of players.
Output
 For each test case, output a single line containing an integer corresponding to the number of players that could mishear the message or whisper it wrongly.
Constraints and Subtasks
 1 ≤ T ≤ 5
 1 ≤ A_{i} ≤ 10^{9}
Subtask 1: 40 points
 2 ≤ N ≤ 10^{3}
Subtask 2: 60 points
 2 ≤ N ≤ 10^{5}
Example
Input: 3 7 1 1 1 3 3 3 2 5 1 3 1 1 1 4 5 5 5 5 Output: 4 3 0
Explanation
 Example 1: The 3rd, 4th, 6th and 7th player could mishear the message or whisper it wrongly.
 Example 2: First 3 players could mishear the message or whisper it wrongly.
Author:  m0stik 
Tester:  xcwgf666 
Editorial  http://discuss.codechef.com/problems/BROKPHON 
Tags  april15, cakewalk, loops, m0stik 
Date Added:  25012015 
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, SCALA, 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, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 