#include <bits/stdc++.h>
using namespace std;
int maxn(int x, int y, int z, int k) {
  x = max(x, y);
  z = max(z, k);
  return max(x, z);
}
long long m, n, i, j, x, y, sum1, sum2, sum3, ans;
int main() {
  string s, ss = "RGBRGB";
  cin >> n;
  while (n--) {
    cin >> x >> y;
    cin >> s;
    ans = 0;
    for (i = 0; i <= x - y; i++) {
      sum1 = sum2 = sum3 = m = 0;
      for (j = 0; j < y; j++) {
        m++;
        if (s[i + j] == ss[m % 3]) sum1++;
      }
      m = 1;
      for (j = 0; j < y; j++) {
        m++;
        if (s[i + j] == ss[m % 3]) sum2++;
      }
      m = 2;
      for (j = 0; j < y; j++) {
        m++;
        if (s[j + i] == ss[m % 3]) sum3++;
      }
      ans = maxn(sum1, sum2, sum3, ans);
    }
    cout << y - ans << endl;
  }
  return 0;
}
