#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const double eps = 1e-7;
int main() {
  int q;
  cin >> q;
  string a = "RGB", b = "GBR", c = "BRG";
  for (int i = 1; i < 800; i++) a += "RGB";
  for (int i = 1; i < 800; i++) b += "GBR";
  for (int i = 1; i < 800; i++) c += "BRG";
  vector<string> vs = {a, b, c};
  while (q--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans = INT_MAX;
    for (int i = 0; i < 3; i++) {
      int lcmn = INT_MAX;
      string sb = vs[i].substr(0, k);
      for (int j = 0; j + k <= n; j++) {
        int df = 0;
        for (int l = 0; l < k; l++) {
          if (sb[l] != s[j + l]) df++;
        }
        lcmn = min(lcmn, df);
      }
      ans = min(lcmn, ans);
    }
    cout << ans << endl;
  }
}
