#include <bits/stdc++.h>
const long long lim = 1e5 + 5;
using namespace std;
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
bool vis[lim];
long long n, m, k, x, y, z, ans, cnt;
vector<long long> adj[100005];
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
long long ck(string x, string y) {
  long long n = x.size();
  long long cnt = 0;
  ;
  for (long long i = 0; i < n; i++)
    if (x[i] != y[i]) cnt++;
  return cnt;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    string s, ss = "";
    cin >> s;
    string s1 = "", s2 = "", s3 = "";
    ;
    for (long long i = 0; i < k; i++) {
      if (i % 3 == 0) {
        s1 += "R";
        s2 += "G";
        s3 += "B";
      } else if (i % 3 == 1) {
        s1 += "G";
        s2 += "B";
        s3 += "R";
      } else if (i % 3 == 2) {
        s1 += "B";
        s2 += "R";
        s3 += "G";
      };
    };
    for (long long i = 0; i < k; i++) ss += s[i];
    long long mn = 1000000007;
    mn = min(mn, min(ck(s1, ss), min(ck(s2, ss), ck(s3, ss))));
    ;
    for (long long i = k; i < n; i++) {
      ss.erase(ss.begin());
      ss += s[i];
      mn = min(mn, min(ck(s1, ss), min(ck(s2, ss), ck(s3, ss))));
    }
    cout << mn << "\n";
  }
}
