#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  string meh = "RGB";
  while (q--) {
    int n, k;
    string cad;
    cin >> n >> k >> cad;
    int ans = n;
    for (int ini = 0; ini + k <= n; ++ini) {
      for (int off = 0; off < 3; ++off) {
        int aux = 0;
        for (int it = 0; it < k; ++it)
          aux += (cad[ini + it] != meh[(off + it) % 3]);
        ans = min(ans, aux);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
