#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
long long fun(string &a, string &b) {
  long long n = a.length(), c = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] != b[i]) c++;
  return (c);
}
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long n, k;
    cin >> n >> k;
    string s, s1, s2, s3;
    cin >> s;
    char ch[] = {'R', 'G', 'B'};
    for (long long i = 0; i < k; i++) {
      s1.push_back(ch[i % 3]);
      s2.push_back(ch[(i + 1) % 3]);
      s3.push_back(ch[(i + 2) % 3]);
    }
    long long m = 2001;
    for (long long i = 0; i <= (n - k); i++) {
      string ss;
      for (long long j = 0; j < k; j++) ss.push_back(s[i + j]);
      m = min(m, fun(ss, s1));
      m = min(m, fun(ss, s2));
      m = min(m, fun(ss, s3));
    }
    cout << m << "\n";
  }
}
