#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f;
char s[maxn];
char str[4] = "RGB";
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n, m;
    scanf("%d%d", &n, &m);
    scanf("%s", s);
    int minn = inf;
    n -= m;
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        int jishu = 0, temp;
        temp = (j <= 1 ? j : 2);
        for (int k = 0; k < m; k++) {
          if (s[i + k] != str[(temp + k) % 3]) {
            jishu++;
          }
        }
        minn = min(minn, jishu);
      }
    }
    printf("%d\n", minn);
  }
}
