#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t, i, j, n, k;
  cin >> t;
  while (t--) {
    string s, str = "RGB";
    cin >> n >> k >> s;
    long long int ans = INT_MAX;
    for (i = 0; i <= n - k; i++) {
      for (long long int pos = 0; pos < 3; pos++) {
        long long int count = 0;
        for (j = i; j < i + k; j++) {
          if (s[j] != str[(pos + j) % 3]) count++;
        }
        ans = min(ans, count);
      }
    }
    cout << ans << "\n";
  }
}
