#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
string str, arr = "RGB";
int t, n, k, sz, ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    ans = 0x3f3f3f3f;
    cin >> n >> k >> str;
    sz = str.length();
    for (int i = 0; i < sz; i++) {
      if (i + k - 1 < sz) {
        for (int kk = 0; kk < 3; kk++) {
          int tmp = 0, idx = kk;
          for (int j = i; j < i + k; j++) {
            if (str[j] != arr[idx]) {
              tmp++;
            }
            idx = (idx + 1) % 3;
          }
          ans = min(ans, tmp);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
