#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, k;
    scanf("%d %d", &n, &k);
    string str, tmp;
    cin >> str;
    int ans = 99999;
    for (int i = 0; i <= n - k; i++) {
      for (int x = 1; x <= 3; x++) {
        tmp = "";
        if (x == 1)
          tmp = "BRG";
        else if (x == 2)
          tmp = "GBR";
        else
          tmp = "RGB";
        int res = 0;
        for (int j = 0; j < k; j++) {
          if (tmp[j % 3] != str[i + j]) res++;
        }
        ans = min(ans, res);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
