#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  string s;
  int n, k;
  string r = "", g = "", b = "";
  vector<string> v;
  for (int i = 0; i < 1500; i++) {
    r += "RGB";
    b += "BRG";
    g += "GBR";
  }
  for (int m = 0; m < q; m++) {
    v.clear();
    cin >> n >> k;
    cin >> s;
    string d;
    for (int i = 0; i < s.length(); i++) {
      d = s.substr(i, k);
      if (d.length() == k) v.push_back(d);
    }
    long long minn = 1e9;
    for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {
      int cntr = 0;
      int cntb = 0;
      int cntg = 0;
      string s1 = (*it);
      for (int i = 0; i < s1.length(); i++) {
        if (s1[i] != r[i]) {
          cntr++;
        }
        if (s1[i] != b[i]) {
          cntb++;
        }
        if (s1[i] != g[i]) {
          cntg++;
        }
      }
      int mio = min(cntr, min(cntb, cntg));
      if (mio < minn) minn = mio;
    }
    cout << minn << endl;
  }
  return 0;
}
