#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, k, m = INT64_MAX;
    cin >> n >> k;
    string s, temp = "RGB";
    cin >> s;
    for (int i = 0; i <= n - k; i++) {
      for (int off = 0; off < 3; off++) {
        long long c = 0;
        for (int j = i; j < i + k; j++) {
          if (s[j] != temp[(off + j) % 3]) c++;
        }
        m = min(m, c);
      }
    }
    cout << m << "\n";
  }
  return 0;
}
