#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
void testCase() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  string ss[] = {"RGB", "BRG", "GBR"};
  int ans = 1e9;
  for (auto txt : ss) {
    for (int i = 0; i + m <= n; i++) {
      int a = 0, count = 0;
      for (int j = i; j < i + m; j++) {
        count += s[j] != txt[a % 3];
        a++;
      }
      ans = min(ans, count);
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    testCase();
  }
  return 0;
}
