#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const long long MOD = 1073741824;
const long long N = 1e6 + 9;
const long long inf = 1 << 30;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <typename T>
T exp(T b, T p) {
  T x = 1;
  while (p) {
    if (p & 1) x = (x * b);
    b = (b * b);
    p = p >> 1;
  }
  return x;
}
inline long long ones(long long n) {
  long long res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
map<char, char> mp;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(0);
  mp['R'] = 'G', mp['G'] = 'B', mp['B'] = 'R';
  long long q;
  cin >> q;
  long long n, k;
  string s;
  while (q--) {
    cin >> n >> k >> s;
    long long ans1 = 1e9;
    for (long long i = 0; i <= n - k; ++i) {
      string tmp = s.substr(i, k);
      long long nextG = 0, nextR = 0, nextB = 0;
      char g = 'G', b = 'B', r = 'R';
      for (long long j = 0; j < tmp.size(); ++j) {
        if (g != tmp[j]) nextG++;
        if (r != tmp[j]) nextR++;
        if (b != tmp[j]) nextB++;
        r = mp[r];
        g = mp[g];
        b = mp[b];
      }
      ans1 = min({ans1, nextB, nextG, nextR});
    }
    cout << ans1 << "\n";
  }
}
