#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const char C[3] = {'R', 'G', 'B'};
int main() {
  std::ios::sync_with_stdio(false);
  char s[maxn];
  int q;
  cin >> q;
  while (q--) {
    int n, k;
    cin >> n >> k >> s;
    int ans = k;
    for (int i = 0; i + k <= n; i++) {
      for (int j = 0; j < 3; j++) {
        int temp = 0;
        for (int p = 0; p < k; p++)
          if (s[i + p] != C[(j + p) % 3]) ++temp;
        ans = min(ans, temp);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
