#include <bits/stdc++.h>
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 9;
const int MAX_N = 2;
const int oo = INT_MAX;
const long long int OO = 1e18;
const int alldx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int alldy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0};
const int dz[] = {0, 0, 0, 0, 1, -1};
using namespace std;
long long int GCD(long long int a, long long int b) {
  return ((!b) ? a : GCD(b, a % b));
}
long long int LCM(long long int a, long long int b) {
  return a / (GCD(a, b)) * b;
}
long long int nCr(long long int n, long long int r) {
  if (n < r) return 0;
  if (r == 0) return 1;
  return n * nCr(n - 1, r - 1) / r;
}
long long int PowMod(long long int bs, long long int ex, long long int M) {
  if (!ex) return 1;
  long long int p = PowMod((bs * bs) % M, ex >> 1, M);
  return (ex & 1) ? (p * bs) % M : p;
}
bool isPrime(long long int n) {
  if (n == 2) return 1;
  if (n < 2 || n % 2 == 0) return 0;
  for (long long int i = 3; i * i <= n; i += 2)
    if (n % i == 0) return 0;
  return 1;
}
bool isPalindrome(string str) {
  long long int l = 0;
  long long int h = str.size() - 1;
  while (h > l) {
    if (str[l++] != str[h--]) {
      return 0;
    }
  }
  return 1;
}
long long int NoOfOdd(long long int L, long long int R) {
  long long int N = (R - L) / 2;
  if (R % 2 != 0 || L % 2 != 0) N++;
  return N;
}
bool isPerfectSquare(long double x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
string s;
string r = "RGB", g = "GBR", b = "BRG";
long long int q, n, k;
long long int GetDiff(string S, string sub) {
  long long int cnt = 0;
  string ans = "";
  for (long long int i = (0) - ((0) > (sub.size()));
       i != (sub.size()) - ((0) > (sub.size()));
       i += 1 - 2 * ((0) > (sub.size()))) {
    if (sub[i] != S[i % 3]) cnt++;
    ans += S[i % 3];
  }
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> n >> k;
    cin >> s;
    long long int ans = n;
    for (long long int i = 0; i <= n - k; i++) {
      string sb = s.substr(i, k);
      ans = min({ans, GetDiff(r, sb), GetDiff(g, sb), GetDiff(b, sb)});
    }
    cout << ans << '\n';
  }
}
