#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  string a = "RGB";
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans = 99999;
    for (int i = 0; i <= n - k; ++i) {
      int b = 0;
      int ct = 0;
      for (int j = i; j < i + k; ++j) {
        if (s[j] != a[b]) ct++;
        b++;
        b = b % 3;
      }
      ans = min(ans, ct);
      b = 1;
      ct = 0;
      for (int j = i; j < i + k; ++j) {
        if (s[j] != a[b]) ct++;
        b++;
        b = b % 3;
      }
      ans = min(ans, ct);
      b = 2;
      ct = 0;
      for (int j = i; j < i + k; ++j) {
        if (s[j] != a[b]) ct++;
        b++;
        b = b % 3;
      }
      ans = min(ans, ct);
    }
    cout << ans << endl;
  }
  return 0;
}
