#include <bits/stdc++.h>
using namespace std;
char ss[3] = {'R', 'G', 'B'};
char s[2000 + 9];
int ans;
int n, k;
void judge(int x, int id) {
  int p = id;
  int tem = 0;
  for (int i = 0; i < k; ++i) {
    if (s[x + i] != ss[p]) ++tem;
    ++p;
    p %= 3;
  }
  ans = min(ans, tem);
}
int main() {
  int qn;
  scanf("%d", &qn);
  while (qn--) {
    scanf("%d %d", &n, &k);
    scanf("%s", &s);
    ans = 0x3f3f3f3f;
    for (int i = 0; i + k - 1 < n; ++i) {
      judge(i, 0);
      judge(i, 1);
      judge(i, 2);
      if (ans == 0) break;
    }
    printf("%d\n", ans);
  }
  return 0;
}
