#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string b = "RGB";
  while (b.length() < 2000) {
    b += b;
  }
  long long t;
  cin >> t;
  while (t--) {
    unordered_map<string, long long> mp;
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long ans = 1000000, m = 0;
    while (true) {
      string tmp = "";
      bool flag = false;
      for (long long i = 0; i <= n - k; i++) {
        long long l = m;
        long long new_ans = 0;
        for (long long j = i; j < i + k; j++) {
          if (!flag) {
            tmp += b[l];
          }
          if (b[l] != s[j]) new_ans++;
          l++;
        }
        if (mp[tmp] == 1) break;
        flag = true;
        ans = min(ans, new_ans);
      }
      if (mp[tmp] == 1) {
        break;
      }
      mp[tmp] = 1;
      m++;
    }
    cout << ans << endl;
  }
  return 0;
}
