#include <bits/stdc++.h>
using namespace std;
string store = "RGB";
int find(string sk, int j) {
  int k = sk.size();
  int cnt = 0;
  for (int t = 0; t < k; t++) {
    if (sk[t] != store[j]) {
      cnt++;
    }
    j++;
    j %= 3;
  }
  return cnt;
}
int solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  string sk = "";
  int mini = INT_MAX;
  for (int i = 0; i < k; i++) {
    sk += s[i];
  }
  for (int j = 0; j < 3; j++) {
    mini = min(mini, find(sk, j));
  }
  for (int i = k; i < n; i++) {
    sk.erase(sk.begin());
    sk += s[i];
    for (int j = 0; j < 3; j++) {
      mini = min(mini, find(sk, j));
    }
  }
  return mini;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cout << solve() << "\n";
  }
}
