#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
char df = '\n';
string a = "RGB";
string b = "GBR";
string c = "BRG";
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int m = INT_MAX;
  for (int i = 0; i + k <= n; i++) {
    int x = 0, y = 0, z = 0;
    for (int j = 0; j < k; j++) {
      if (s[i + j] != a[j % 3]) x++;
      if (s[i + j] != b[j % 3]) y++;
      if (s[i + j] != c[j % 3]) z++;
    }
    m = min({m, x, y, z});
  }
  cout << m << df;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tt = 1;
  cin >> tt;
  while (tt--) solve();
  return 0;
}
