#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, n, k;
  string s;
  cin >> q;
  while (q--) {
    cin >> n >> k >> s;
    string rgb = "RGB";
    int cnt = 0, ans = k;
    for (int i = 0; i <= n - k; i++) {
      for (int j = 0; j < 3; j++) {
        cnt = 0;
        for (int m = 0; m < k; m++)
          if (s[i + m] != rgb[(j + m) % 3]) cnt++;
        if (cnt < ans) ans = cnt;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
