#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans = INT_MAX;
    string temp = "RGB";
    for (int i = 0; i <= s.size() - k; i++) {
      for (int ke = 0; ke < 3; ke++) {
        int x = 0;
        for (int j = 0; j < k; j++) {
          if (s[i + j] != temp[(j + ke) % 3]) {
            x++;
          }
        }
        ans = min(ans, x);
      }
    }
    cout << ans << endl;
  }
}
