#include <bits/stdc++.h>
const long double pi = 2 * acos(0.0);
using namespace std;
string s1 = "RGB", s2 = "GBR", s3 = "BRG";
long long fun(string s1, string s2) {
  long long ans = 0;
  for (long long i = 0; i < (long long)s1.size(); ++i)
    if (s1[i] != s2[i % 3]) ++ans;
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n, k, ans;
    string s;
    cin >> n >> k >> s;
    ans = n;
    for (long long i = 0; i <= n - k; ++i) {
      string temp = s.substr(i, k);
      ans = min(ans, min(fun(temp, s1), min(fun(temp, s2), fun(temp, s3))));
    }
    cout << ans << endl;
  }
  return 0;
}
