#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 2;
const int MAXD = 1e4 + 5;
const int MOD = 1e9 + 7;
const long double EPS = 1e-4;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long a, long long b) {
  long long c = rng();
  return a + ((long long)abs(c)) % (b - a + 1);
}
int calc(string &s, string &t) {
  int ret = 0;
  for (int i = 0; i < (int)s.size(); i++) ret += (s[i] != t[i]);
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    string a, b, c;
    a = "RGB";
    b = "GBR";
    c = "BRG";
    string ta, tb, tc;
    for (int i = 0; i < k; i++) {
      ta.push_back(a[i % 3]);
      tb.push_back(b[i % 3]);
      tc.push_back(c[i % 3]);
    }
    vector<string> v;
    v.push_back(ta);
    v.push_back(tb);
    v.push_back(tc);
    int ans = (int)s.size();
    for (auto &t : v) {
      string tmp;
      for (int i = 0; i < k; i++) {
        tmp.push_back(s[i]);
      }
      ans = min(ans, calc(tmp, t));
      for (int i = k; i < n; i++) {
        tmp.erase(tmp.begin());
        tmp.push_back(s[i]);
        ans = min(ans, calc(tmp, t));
      }
    }
    cout << ans << '\n';
  }
}
