#include <bits/stdc++.h>
using namespace std;
inline int D() {
  int t;
  scanf("%d", &t);
  return t;
}
inline long long llD() {
  long long t;
  scanf("%lld", &t);
  return t;
}
long long MOD = 998244353;
const int N = 1e3 + 3, M = 5;
int arr[N];
int dp[N][N];
int OO = 1e6;
long long n, m, k, T;
string str, ans;
int main() {
  string v = "RGB";
  cin >> T;
  while (T--) {
    cin >> n >> k;
    cin >> ans;
    vector<string> vec;
    for (int i = 0; i < 3; ++i) {
      int x = i;
      string str = "";
      while ((int)(str.size()) < k) {
        str += v[x++];
        x %= 3;
      }
      vec.push_back(str);
    }
    int MN = 1e9;
    for (int i = 0; i < n - k + 1; ++i) {
      for (int j = 0; j < 3; ++j) {
        int x = 0;
        for (int h = i, val = 0; val < k; ++val, ++h)
          x += (vec[j][val] != ans[h]);
        MN = min(MN, x);
      }
    }
    cout << MN << "\n";
  }
}
