Given an array of n integers, the task is to find the number of subarrays whose minimal and maximum elements are same.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an integer N and the second line contains N space separated array elements.

**Output:**

For each test case, print the count of required subarrays in new line.

**Constraints:**

1<=T<=100

1<=N<=10^{5}

1<=A[i]<=10^{5}

**Example:
Input:**

2

4

1 2 3 4

3

1 1 3

**Output:**

4

4

**Explanation:**

```
Input: 1 1 3
Output: 4
Explanation: The subarrays are
(1), (1), (3) and (1, 1)
```

Author: arun03

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

shivam123ahuja | 32 |

rajupraaa1234 | 29 |

Ramchoudhary1 | 24 |

ronak_agarwal | 24 |

NoobieCoder1 | 18 |

mr_kksparrow | 433 |

arpit_anshuman | 228 |

manvirag982 | 224 |

TheHandle | 197 |

ronak_agarwal | 190 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.