#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    string rgb = "RGB";
    long long ans = INT_MAX;
    for (long long i = 0; i < n - k + 1; i++) {
      for (long long off = 0; off < 3; off++) {
        long long cur = 0;
        for (long long pos = 0; pos < k; pos++) {
          if (s[i + pos] != rgb[(off + pos) % 3]) cur++;
        }
        ans = min(ans, cur);
      }
    }
    cout << ans << endl;
  }
}
