Devu is a class teacher of a class of n students. One day, in the morning prayer of the school, all the students of his class were standing in a line. You are given information of their arrangement by a string s. The string s consists of only letters 'B' and 'G', where 'B' represents a boy and 'G' represents a girl.
Devu wants inter-gender interaction among his class should to be maximum. So he does not like seeing two or more boys/girls standing nearby (i.e. continuous) in the line. e.g. he does not like the arrangements BBG and GBB, but he likes BG, GBG etc.
Now by seeing the initial arrangement s of students, Devu may get furious and now he wants to change this arrangement into a likable arrangement. For achieving that, he can swap positions of any two students (not necessary continuous). Let the cost of swapping people from position i with position j (i ≠ j) be c(i, j). You are provided an integer variable type, then the cost of the the swap will be defined by c(i, j) = |j − i|type.

Please help Devu in finding minimum cost of swaps needed to convert the current arrangement into a likable one.

-----Input-----
The first line of input contains an integer T, denoting the number of test cases. Then T test cases are follow.
The first line of each test case contains an integer type, denoting the type of the cost function. Then the next line contains string s of length n, denoting the initial arrangement s of students.
Note that the integer n is not given explicitly in input.

-----Output-----
For each test case, print a single line containing the answer of the test case, that is, the minimum cost to convert the current arrangement into a likable one. If it is not possible to convert the current arrangement into a likable one, then print -1 instead of the minimum cost.

-----Constraints and Subtasks-----Subtask 1: 25 points
- 1 ≤ T ≤ 105
- 1 ≤ n ≤ 105
- type = 0
- Sum of n over all the test cases in one test file does not exceed 106. 
Subtask 2: 25 points
- 1 ≤ T ≤ 105
- 1 ≤ n ≤ 105
- type = 1
- Sum of n over all the test cases in one test file does not exceed 106. 
Subtask 3: 25 points
- 1 ≤ T ≤ 105
- 1 ≤ n ≤ 105
- type = 2
- Sum of n over all the test cases in one test file does not exceed 106. 
Subtask 4: 25 points
- 1 ≤ T ≤ 102
- 1 ≤ n ≤ 103
- type can be 0, 1 or 2, that is type ∈ {0, 1, 2}.

-----Example-----
Input:
8
0
BB
0
BG
0
BBGG
1
BGG
1
BGGB
1
BBBGG
2
BBGG
2
BGB

Output:
-1
0
1
1
1
3
1
0

-----Explanation-----
Note type of the first 3 test cases is 0. So c(i, j) = 1. Hence we just have to count minimum number of swaps needed.
Example case 1. There is no way to make sure that both the boys does not stand nearby. So answer is -1.
Example case 2. Arrangement is already valid. No swap is needed. So answer is 0.
Example case 3. Swap boy at position 1 with girl at position 2. After swap the arrangement will be BGBG which is a valid arrangement. So answer is 1.
Now type of the next 3 test cases is 1. So c(i, j) = |j − i|, that is, the absolute value of the difference between i and j.
Example case 4. Swap boy at position 0 with girl at position 1. After swap the arrangement will be GBG which is a valid arrangement. So answer is |1 - 0| = 1.
Example case 5. Swap boy at position 0 with girl at position 1. After swap the arrangement will be GBGB which is a valid arrangement. So answer is |1 - 0| = 1.
Example case 6. Swap boy at position 1 with girl at position 4. After swap the arrangement will be BGBGB which is a valid arrangement. So answer is |4 - 1| = 3.
Then type of the last 2 test cases is 2. So c(i, j) = (j − i)2
Example case 7. Swap boy at position 1 with girl at position 2. After swap the arrangement will be BGBG which is a valid arrangement. So answer is (2 - 1)2 = 1.
Example case 8. Arrangement is already valid. No swap is needed. So answer is 0.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "def actual_generator(a,N,start):\n result = []\n if a == 'B':\n  result = ['B', 'G'] * (N // 2)\n  result.append('B')\n elif a == 'G':\n  result = ['G', 'B'] * (N // 2)\n  result.append('G')\n else:\n  if start == 'B':\n   result = ['B', 'G'] * (N // 2)\n  elif start == 'G':\n   result = ['G', 'B'] * (N // 2)\n return result\n\n\nfor _ in range(int(input())):\n typ = int(input())\n s = input()\n N = len(s)\n array = [s[i] for i in range(N)]\n countG = array.count('G')\n countB = array.count('B')\n if abs(countG - countB) > 1:\n  print(-1)\n else:\n  defectB = []\n  defectG = []\n  if countG == countB:\n   actual1 = actual_generator('X', N, 'B')\n   actual2 = actual_generator('X', N, 'G')\n   defect1B = []\n   defect1G = []\n   defect2B = []\n   defect2G = []\n   for i in range(N):\n    if actual1[i] != array[i] and actual1[i] == 'B':\n     defect1B.append(i)\n    elif actual1[i] != array[i] and actual1[i] == 'G':\n     defect1G.append(i)\n   for i in range(N):\n    if actual2[i] != array[i] and actual2[i] == 'B':\n     defect2B.append(i)\n    elif actual2[i] != array[i] and actual2[i] == 'G':\n     defect2G.append(i)\n   if len(defect1B) > len(defect2B):\n    defectG = defect2G\n    defectB = defect2B\n   else :\n    defectG = defect1G\n    defectB = defect1B\n  elif countG > countB:\n   actual = actual_generator('G', N, 'X')\n   defectB = []\n   defectG = []\n   for i in range(N):\n    if actual[i] != array[i] and actual[i] == 'B':\n     defectB.append(i)\n    elif actual[i] != array[i] and actual[i] == 'G':\n     defectG.append(i)\n\n  elif countB > countG:\n   actual = actual_generator('B', N, 'X')\n   defectB = []\n   defectG = []\n   for i in range(N):\n    if actual[i] != array[i] and actual[i] == 'B':\n     defectB.append(i)\n    elif actual[i] != array[i] and actual[i] == 'G':\n     defectG.append(i)\n\n  if typ == 0 :\n   print(len(defectB))\n  elif typ == 1 :\n   print(abs(sum(defectG)-sum(defectB)))"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14579