The only difference between easy and hard versions is the size of the input.

You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.

You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there will be a string of length $k$ that is a substring of $s$, and is also a substring of the infinite string "RGBRGBRGB ...".

A string $a$ is a substring of string $b$ if there exists a positive integer $i$ such that $a_1 = b_i$, $a_2 = b_{i + 1}$, $a_3 = b_{i + 2}$, ..., $a_{|a|} = b_{i + |a| - 1}$. For example, strings "GBRG", "B", "BR" are substrings of the infinite string "RGBRGBRGB ..." while "GR", "RGR" and "GGG" are not.

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 2000$) — the number of queries. Then $q$ queries follow.

The first line of the query contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the length of the string $s$ and the length of the substring.

The second line of the query contains a string $s$ consisting of $n$ characters 'R', 'G' and 'B'.

It is guaranteed that the sum of $n$ over all queries does not exceed $2000$ ($\sum n \le 2000$).


-----Output-----

For each query print one integer — the minimum number of characters you need to change in the initial string $s$ so that after changing there will be a substring of length $k$ in $s$ that is also a substring of the infinite string "RGBRGBRGB ...".


-----Example-----
Input
3
5 2
BGGGG
5 3
RBRGR
5 5
BBBRR

Output
1
0
3



-----Note-----

In the first example, you can change the first character to 'R' and obtain the substring "RG", or change the second character to 'R' and obtain "BR", or change the third, fourth or fifth character to 'B' and obtain "GB".

In the second example, the substring is "BRG".
[{"code": "import sys\ndef countR(ip):\n    c=0\n    for i in ip:\n        if(i=='R'):\n            c+=1\n    return c\n    \ndef countB(ip):\n    c=0\n    for i in ip:\n        if(i=='B'):\n            c+=1\n    return c\n    \ndef countG(ip):\n    c=0\n    for i in ip:\n        if(i=='G'):\n            c+=1\n    return c\n# sys.stdin.readline()\nt=int(sys.stdin.readline())\nx='RGB'*680\ny='GBR'*680\nz='BRG'*680\nfor i in range(t):\n    n,k=list(map(int,sys.stdin.readline().strip().split()))\n    a=sys.stdin.readline().strip()\n    xk=x[:k]\n    yk=y[:k]\n    zk=z[:k]\n    # print(k,xk,zk)\n    # xc=[]\n    # yc=[]\n    # zc=[]\n    # xc.append(countR(xk))\n    # xc.append(countG(xk))\n    # xc.append(countB(xk))\n   \n    # yc.append(countR(yk))\n    # yc.append(countG(yk))\n    # yc.append(countB(yk))\n    \n    # zc.append(countR(zk))\n    # zc.append(countG(zk))\n    # zc.append(countB(zk))\n    op=2001\n    for j in range(n-k+1):\n        b=a[j:j+k]\n        # print(len(b),xc,zc)\n        # bc=[]\n        \n        # bc.append(countR(b))\n        # bc.append(countG(b))\n        # bc.append(countB(b))\n        xd=0\n        yd=0\n        zd=0\n        # print(a,b,xc,yc,zc,bc)\n        for jj in range(len(b)):\n            if(b[jj]!=xk[jj]):\n                xd+=1\n            if(b[jj]!=yk[jj]):\n                yd+=1\n            if(b[jj]!=zk[jj]):\n                zd+=1\n         # print(a,b,xd,yd,zd,z)\n        op=min(op,xd,yd,zd)\n    print(op)\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "def givestringsk(k):\n    t=[\"R\",\"G\",\"B\"]\n    ans=[]\n    for i in range(3):\n        temp=\"\"\n        for j in range(i,i+k):\n            temp+=t[j%3]\n        ans.append(temp)\n    return ans\ndef countdifferences(a,b):\n    cnt=0\n    for i in range(len(a)):\n        if a[i]!=b[i]:cnt+=1\n    return cnt\nfor _ in range(int(input())):\n    n,k=list(map(int,input().split()))\n    s=input()\n    temp=givestringsk(k)\n    ans=10000000000000\n    for i in range(k,n+1):\n        for j in range(3):\n            ans=min(ans,countdifferences(s[i-k:i],temp[j]))\n    print(ans)\n", "passed": true, "time": 0.15, "memory": 14228.0, "status": "done"}, {"code": "s=\"RGB\"*666\nrgb=[\"GB\"+s]\nrgb.append(\"RGB\"+s)\nrgb.append(\"BRGB\"+s)\nfor _ in range(int(input())):\n\tn,k=map(int,input().split())\n\tt=input()\n\tl=len(t)\n\tans=2001\n\ta=[0]*l\n\tfor i in range(3):\n\t\ta[0]=1 if rgb[i][0]!=t[0] else 0\n\t\tfor j in range(1,l):\n\t\t\ta[j]=a[j-1]+(1 if rgb[i][j]!=t[j] else 0)\n\t\tans=min(ans,a[k-1])\n\t\tfor j in range(k,l):\n\t\t\tans=min(ans,a[j]-a[j-k])\n\tprint(ans)", "passed": true, "time": 0.14, "memory": 14056.0, "status": "done"}, {"code": "q = int(input())\nfor _ in range(q):\n    n, k = map(int, input().split())\n    s = input()\n    ans = k\n    sample = \"RGB\"\n    for i in range(n - k + 1):\n        cnt = 0\n        x = 0\n        for j in range(i, i + k):\n            if s[j] != sample[x]:\n                cnt += 1\n            x = (x + 1) % 3\n        #print(ans, 7)\n        ans = min(ans, cnt)\n        cnt = 0\n        x = 1\n        for j in range(i, i + k):\n            if s[j] != sample[x]:\n                cnt += 1\n            x = (x + 1) % 3\n        ans = min(ans, cnt)\n        #print(ans, 8)\n        cnt = 0\n        x = 2\n        for j in range(i, i + k):\n            if s[j] != sample[x]:\n                cnt += 1\n            x = (x + 1) % 3\n        ans = min(ans, cnt) \n        #print(ans, 9)       \n    print(ans)", "passed": true, "time": 0.25, "memory": 14240.0, "status": "done"}, {"code": "def main():\n    q = int(input())\n    for i in range(q):\n        n, k = map(int, input().split())\n        s = input()\n        min_ans = 10 ** 9\n        for i in range(n - k + 1):\n            count1 = 0\n            count2 = 0\n            count3 = 0\n            for j in range(k):\n                if (i + j) % 3 == 0:\n                    if s[i + j] != \"R\":\n                        count1 += 1\n                    if s[i + j] != \"G\":\n                        count2 += 1\n                    if s[i + j] != \"B\":\n                        count3 += 1\n                if (i + j) % 3 == 1:\n                    if s[i + j] != \"G\":\n                        count1 += 1\n                    if s[i + j] != \"B\":\n                        count2 += 1\n                    if s[i + j] != \"R\":\n                        count3 += 1 \n                if (i + j) % 3 == 2:\n                    if s[i + j] != \"B\":\n                        count1 += 1\n                    if s[i + j] != \"R\":\n                        count2 += 1\n                    if s[i + j] != \"G\":\n                        count3 += 1 \n            min_ans = min(min_ans, count1, count2, count3)\n        print(min_ans)\nmain()", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "q = int(input())\nb = []\nfor m in range(q):\n    n, k = list(map(int, input().split()))\n    l = input()\n    k1 = 'R'\n    k2 = 'G'\n    k3 = 'B'\n    for i in range(1, k):\n        if k1[i - 1] == 'R':\n            k1 = k1 + 'G'\n        if k1[i - 1] == 'G':\n            k1 = k1 + 'B'\n        if k1[i - 1] == 'B':\n            k1 = k1 + 'R'\n        if k2[i - 1] == 'R':\n            k2 = k2 + 'G'\n        if k2[i - 1] == 'G':\n            k2 = k2 + 'B'\n        if k2[i - 1] == 'B':\n            k2 = k2 + 'R'\n        if k3[i - 1] == 'R':\n            k3 = k3 + 'G'\n        if k3[i - 1] == 'G':\n            k3 = k3 + 'B'\n        if k3[i - 1] == 'B':\n            k3 = k3 + 'R'\n    minn = n\n    #print(k1)\n    #print(k2)\n    #print(k3)\n    for i in range(n - k + 1):\n        tec = 0\n        for j in range(k):\n            if l[i + j] != k1[j]:\n                tec += 1\n        if tec < minn: minn = tec\n    for i in range(n - k + 1):\n        tec = 0\n        for j in range(k):\n            if l[i + j] != k2[j]:\n                tec += 1\n        if tec < minn: minn = tec\n    for i in range(n - k + 1):\n        tec = 0\n        for j in range(k):\n            if l[i + j] != k3[j]:\n                tec += 1\n                #print(l[i+j], k3[j])\n        if tec < minn: minn = tec\n    b.append(minn)\nfor i in range(q):\n    print(b[i])\n", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "from sys import stdin\nfrom collections import deque\nc=int(stdin.readline().strip())\nfor cas in range(c):\n    n,m=list(map(int,stdin.readline().strip().split()))\n    s=deque(stdin.readline().strip())\n    arr=[\"R\",\"G\",\"B\"]\n    ans=n+3\n    for k in range(1):\n\n        for  i in range(3):\n            x=i\n\n            dp=[0 for i in range(n+1)]\n            for j in range(n):\n\n                if s[j]!=arr[x]:\n                    dp[j+1]+=1\n                dp[j+1]+=dp[j]\n                if j+1>=m:\n\n                    ans=min(ans,dp[j+1]-dp[j+1-m])\n                x+=1\n                x=x%3\n\n    print(ans)\n                \n            \n    \n            \n            \n1\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "def user99():\n    text = 'RGB' * 2222\n    for _ in range(int(input())):\n        n, k = list(map(int, input().split()))\n        s = input()\n        ans = 2222\n        for i in range(3):\n            p = text[i: k + i]\n            #print(\"p = \", p)\n            for j in range(n - k + 1):\n                diff = 0\n                #print(s[j: j + k], \"vs\", p)\n                for l in range(j, j + k):\n                    if s[l] != p[l - j]:\n                        diff += 1\n                ans = min(ans, diff)\n        print(ans)\n\nuser99()\n", "passed": true, "time": 0.24, "memory": 14072.0, "status": "done"}, {"code": "Q = int(input())\nfor _ in range(Q):\n    N, K = list(map(int, input().split()))\n    S = input()\n    X = [{\"R\":0, \"G\":1, \"B\":2}[s] for s in S]\n    mi = K\n    for i in range(3):\n        d = 0\n        for j in range(N):\n            if X[j] != (i+j) % 3:\n                d += 1\n            if j >= K and X[j-K] != (i+j-K) % 3:\n                d -= 1\n            if j >= K-1:\n                mi = min(mi, d)\n    print(mi)\n", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "R = lambda: map(int, input().split())\nfor _ in range(int(input())):\n    n,k = R()\n    s = input()\n    p = (k+2)//2\n    l = \"RGB\"*p\n    res = n\n    for i in range(n-k+1):\n        c = 0\n        #print(l[0:k])\n        for j in range(0,k):\n            c += (s[i+j] != l[j])\n        res = min(res,c)\n        #print(c)\n        c = 0\n        #print(l[1:k+1])\n        for j in range(1,k+1):\n            c += (s[i+j-1] != l[j])\n        res = min(res,c)\n        #print(c)\n        c = 0\n        #print(l[2:k+2])\n        for j in range(2,k+2):\n            c += (s[i+j-2] != l[j])\n        res = min(res,c)\n        #print(c)\n    print(res)", "passed": true, "time": 0.14, "memory": 14148.0, "status": "done"}, {"code": "R = lambda: map(int, input().split())\nfor _ in range(int(input())):\n    n,k = R()\n    s = input()\n    p = (k+2)//2\n    l = \"RGB\"*p\n    res = n\n    for i in range(n-k+1):\n        c = 0\n        #print(l[0:k])\n        for j in range(0,k):\n            c += (s[i+j] != l[j])\n        res = min(res,c)\n        #print(c)\n        c = 0\n        #print(l[1:k+1])\n        for j in range(1,k+1):\n            c += (s[i+j-1] != l[j])\n        res = min(res,c)\n        #print(c)\n        c = 0\n        #print(l[2:k+2])\n        for j in range(2,k+2):\n            c += (s[i+j-2] != l[j])\n        res = min(res,c)\n        #print(c)\n    print(res)", "passed": true, "time": 0.98, "memory": 14308.0, "status": "done"}, {"code": "import math\n\n\nclass Read:\n    @staticmethod\n    def int():\n        return int(input())\n\n    @staticmethod\n    def list(sep=' '):\n        return input().split(sep)\n\n    @staticmethod\n    def list_int(sep=' '):\n        return list(map(int, input().split(sep)))\n\n\ndef solve():\n    n, k = Read.list_int()\n    s = input()\n\n    sf = 'RGB' * (k + 2)\n\n    max_s = 0\n    for i in range(n - k + 1):\n        for j in range(3):\n            count = 0\n            for b in range(k):\n                if sf[j + b] == s[i + b]:\n                    count += 1\n            if count > max_s:\n                max_s = count\n\n    print(k - max_s)\n\n\nquery_count = Read.int()\nfor j in range(query_count):\n    solve()\n", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "def solve(d, n, k):\n    mv = sum(d[0:k])\n    v = mv\n    for i in range(1, n-k+1):\n        mv = mv + d[i+k-1] - d[i-1]\n        v = min(v, mv)\n    return v\n\nfor _ in range(int(input())):\n    n, k = tuple(map(int, input().split()))\n    s = input()\n    st = 'RGB' * (n//3 + 3)\n    diff1, diff2, diff3 = [0 for _ in range(n)], [0 for _ in range(n)], [0 for _ in range(n)]\n\n    for i in range(n):\n        if s[i] != st[i]: diff1[i] = 1\n        if s[i] != st[i+1]: diff2[i] = 1\n        if s[i] != st[i+2]: diff3[i] = 1\n\n    print(min(solve(diff1, n, k), solve(diff2, n, k), solve(diff3, n, k)))", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "'''input\n3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n'''\nimport sys\nfrom collections import defaultdict as dd\n\nmod=10**9+7\n\ndef ri(flag=0):\n\tif flag==0:\n\t\treturn [int(i) for i in sys.stdin.readline().split()]\n\telse:\n\t\treturn int(sys.stdin.readline())\n\n\nfor _ in range(int(input())):\n\tn,k = ri()\n\ta = input()\n\trgb= [0 for i in range(n)]\n\tgbr= [0 for i in range(n)]\n\tbrg= [0 for i in range(n)]\n\n\tfor i in range(n):\n\t\tif i%3==0:\n\t\t\tif a[i]!=\"R\":\n\t\t\t\trgb[i]+=1\n\t\tif i%3==1:\n\t\t\tif a[i]!=\"G\":\n\t\t\t\trgb[i]+=1\n\t\tif i%3==2:\n\t\t\tif a[i]!=\"B\":\n\t\t\t\trgb[i]+=1\n\n\tfor i in range(n):\n\t\tif i%3==0:\n\t\t\tif a[i]!=\"G\":\n\t\t\t\tgbr[i]+=1\n\t\tif i%3==1:\n\t\t\tif a[i]!=\"B\":\n\t\t\t\tgbr[i]+=1\n\t\tif i%3==2:\n\t\t\tif a[i]!=\"R\":\n\t\t\t\tgbr[i]+=1\n\n\tfor i in range(n):\n\t\tif i%3==0:\n\t\t\tif a[i]!=\"B\":\n\t\t\t\tbrg[i]+=1\n\t\tif i%3==1:\n\t\t\tif a[i]!=\"R\":\n\t\t\t\tbrg[i]+=1\n\t\tif i%3==2:\n\t\t\tif a[i]!=\"G\":\n\t\t\t\tbrg[i]+=1\n\n\tfor i in range(1,n):\n\t\trgb[i]+=rgb[i-1]\n\t\tbrg[i]+=brg[i-1]\n\t\tgbr[i]+=gbr[i-1]\n\n\n\tans = 999999999\n\t#print(rgb,gbr,brg)\n\tfor i in range(k-1,n):\n\t\t#print(i,i-k)\n\t\tif i-k ==-1:\n\t\t\tans = min(ans,rgb[i],gbr[i],brg[i])\n\t\telse:\n\t\t\tans = min(ans, rgb[i]- rgb[i-k] , gbr[i]- gbr[i-k], brg[i]- brg[i-k] )\n\n\tprint(ans)\n\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "q = int(input())\nfor t in range(q):\n    n, k = list(map(int, input().split()))\n    rgb = input()\n    dp = [0] * 3\n    dp[0] = [0] * (n + 1)\n    dp[1] = [0] * (n + 1)\n    dp[2] = [0] * (n + 1)\n    for i in range(0, n):\n        if rgb[i] == 'R':\n            dp[0][i + 1] = dp[2][i]\n            dp[1][i + 1] = dp[0][i] + 1\n            dp[2][i + 1] = dp[1][i] + 1\n        if rgb[i] == 'G':\n            dp[0][i + 1] = dp[2][i] + 1\n            dp[1][i + 1] = dp[0][i]\n            dp[2][i + 1] = dp[1][i] + 1\n        if rgb[i] == 'B':\n            dp[0][i + 1] = dp[2][i] + 1\n            dp[1][i + 1] = dp[0][i] + 1\n            dp[2][i + 1] = dp[1][i]\n    repl = k\n    dif = k % 3\n    for j in range(3):\n        for i in range(1, n - k + 2):\n            repl = min(repl, -dp[j][i - 1] + dp[(j + dif) % 3][i + k - 1])\n    print(repl)\n", "passed": true, "time": 0.14, "memory": 14244.0, "status": "done"}, {"code": "######################################################################\n# Write your code here\nimport sys\ninput = sys.stdin.readline\n#import resource\n#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])\n#sys.setrecursionlimit(0x100000)\n# Write your code here\nRI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]\nrw = lambda : input().strip().split()\nfrom collections import defaultdict as df\n#import heapq \n#heapq.heapify(li) heappush(li,4) heappop(li)\nimport random\n#random.shuffle(list)\ninfinite = float('inf')\n#######################################################################\n\nt=int(input())\n\nfor _ in range(t):\n    n,k=RI()\n    s=input()\n\n    mini=n\n    \n    test=\"RGB\"*(k//3 + 5)\n    for i in range(n-k+1):\n        count=0\n        \n        for j in range(k):\n            if(s[i+j]!=test[j]):\n                count+=1\n\n        mini=min(count,mini)\n\n    test=\"GBR\"*(k//3 + 5)\n    for i in range(n-k+1):\n        count=0\n        \n        for j in range(k):\n            if(s[i+j]!=test[j]):\n                count+=1\n\n        mini=min(count,mini)\n\n    test=\"BRG\"*(k//3 + 5)\n    for i in range(n-k+1):\n        count=0\n        \n        for j in range(k):\n            if(s[i+j]!=test[j]):\n                count+=1\n\n        mini=min(count,mini)\n\n    print(mini)\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "from sys import stdin,stdout\ninput=stdin.readline\nfor _ in range(int(input())):\n    x=10**5\n    n,k=list(map(int,input().split()))\n    s=input()\n    ans=10**9\n    for i in range(n-k+1):\n        x=s[i:i+k]\n        m=0\n        curr=['R','G','B']\n        for l in range(3):\n            m=0\n            z=l\n            for j in x:\n                if j!=curr[z]:\n                    m+=1\n                z+=1\n                z%=3\n            ans=min(ans,m)\n    print(ans)\n", "passed": true, "time": 0.15, "memory": 14220.0, "status": "done"}, {"code": "######################################################################\n# Write your code here\nimport sys\ninput = sys.stdin.readline\n#import resource\n#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])\n#sys.setrecursionlimit(0x100000)\n# Write your code here\nRI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]\nrw = lambda : input().strip().split()\n#from collections import defaultdict as df\n#import heapq \n#heapq.heapify(li) heappush(li,4) heappop(li)\n#import random\n#random.shuffle(list)\ninfinite = float('inf')\n#######################################################################\n\nt=int(input())\n\nfor _ in range(t):\n    n,k=RI()\n    s=input()\n\n    mini=n\n    \n    test=\"RGB\"*(k//3 + 5)\n    for i in range(n-k+1):\n        count=0\n        \n        for j in range(k):\n            if(s[i+j]!=test[j]):\n                count+=1\n\n        mini=min(count,mini)\n\n    test=\"GBR\"*(k//3 + 5)\n    for i in range(n-k+1):\n        count=0\n        \n        for j in range(k):\n            if(s[i+j]!=test[j]):\n                count+=1\n\n        mini=min(count,mini)\n\n    test=\"BRG\"*(k//3 + 5)\n    for i in range(n-k+1):\n        count=0\n        \n        for j in range(k):\n            if(s[i+j]!=test[j]):\n                count+=1\n\n        mini=min(count,mini)\n\n    print(mini)\n", "passed": true, "time": 0.22, "memory": 14164.0, "status": "done"}, {"code": "import sys\ninput = lambda: sys.stdin.readline().strip()\nfrom math import ceil\n\ndef mismatch(s1, s2):\n    cnt = 0\n    for i in range(len(s1)):\n        if s1[i]!=s2[i]: cnt+=1\n    return cnt\n\nT = int(input())\nfor _ in range(T):\n    n, k = list(map(int, input().split()))\n    check = ''\n    for i in range(ceil((k+2)/3)):\n        check+='RGB'\n    ls = []\n    for i in range(3):\n        ls.append(check[i:i+k])\n    s = input()\n    m = n\n    for i in range(n-k+1):\n        for j in ls:\n            m = min(m, mismatch(s[i:i+k], j))\n    print(m)\n", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "T=int(input())\nfor _ in range(T):\n    n,k=list(map(int,input().split()))\n    s=input()\n    rq1=''\n    rq2=''\n    rq3=''\n\n    for i in range(k):\n        if(i%3==0):\n            rq1=rq1+'R'\n            rq2=rq2+'G'\n            rq3=rq3+'B'\n        elif(i%3==1):\n            rq1=rq1+'G'\n            rq2=rq2+'B'\n            rq3=rq3+'R'\n        elif(i%3==2):\n            rq1=rq1+'B'\n            rq2=rq2+'R'\n            rq3=rq3+'G'\n\n    ans=1000000000000000000\n\n    for i in range(0,len(s)-k+1):\n\n        a1=0\n        a2=0\n        a3=0\n\n        for j in range(i,i+k):\n\n            if(s[j]!=rq1[j-i]):\n                a1+=1\n            if(s[j]!=rq2[j-i]):\n                a2+=1\n            if(s[j]!=rq3[j-i]):\n                a3+=1\n        #print(a1,a2,a3,rq1,rq2,rq3)\n\n        ans=min(ans,min(a1,a2,a3))\n\n    print(ans)\n            \n            \n    \n            \n        \n", "passed": true, "time": 0.22, "memory": 14200.0, "status": "done"}, {"code": "q=int(input())\nfor i in range(q):\n\tn,k=map(int,input().split())\n\ts=input()\n\tm=10**4\n\tfor j in range(n):\n\t\tif j+k<=n:\n\t\t\tl1=[\"R\",\"G\",\"B\"]\n\t\t\tm1,m2,m3=0,0,0\n\t\t\tfor i in range(j,j+k):\n\t\t\t\tif l1[(i-j)%3]!=s[i]:\n\t\t\t\t\tm1+=1\n\t\t\tfor i in range(j,j+k):\n\t\t\t\tif l1[(i+1-j)%3]!=s[i]:\n\t\t\t\t\tm2+=1\n\t\t\tfor i in range(j,j+k):\n\t\t\t\tif l1[(i+2-j)%3]!=s[i]:\n\t\t\t\t\tm3+=1\n\t\t\tm=min(m,m1,m2,m3)\n\t\telse:\n\t\t\tbreak\n\tprint(m)", "passed": true, "time": 0.14, "memory": 14076.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\nq = int(input())\nfor i in range(q):\n    n, k = map(int, input().split())\n    s = input()\n    R, G, B = 0, 0, 0\n    ans = float('inf')\n    for j in range(n):\n        if j % 3 == 0:\n            if s[j] == 'R':\n                G += 1\n                B += 1\n            elif s[j] == 'G':\n                R += 1\n                B += 1\n            else:\n                R += 1\n                G += 1\n        elif j % 3 == 1:\n            if s[j] == 'R':\n                G += 1\n                R += 1\n            elif s[j] == 'G':\n                G += 1\n                B += 1\n            else:\n                R += 1\n                B += 1\n        else:\n            if s[j] == 'R':\n                R += 1\n                B += 1\n            elif s[j] == 'G':\n                R += 1\n                G += 1\n            else:\n                G += 1\n                B += 1\n        if j >= k - 1:\n            ans = min(ans, R, G, B)\n            if (j - k + 1) % 3 == 0:\n                if s[j - k + 1] == 'R':\n                    G -= 1\n                    B -= 1\n                elif s[j - k + 1] == 'G':\n                    R -= 1\n                    B -= 1\n                else:\n                    R -= 1\n                    G -= 1\n            elif (j - k + 1) % 3 == 1:\n                if s[j - k + 1] == 'R':\n                    G -= 1\n                    R -= 1\n                elif s[j - k + 1] == 'G':\n                    G -= 1\n                    B -= 1\n                else:\n                    R -= 1\n                    B -= 1\n            else:\n                if s[j - k + 1] == 'R':\n                    R -= 1\n                    B -= 1\n                elif s[j - k + 1] == 'G':\n                    R -= 1\n                    G -= 1\n                else:\n                    G -= 1\n                    B -= 1\n\n    print(ans)", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}]