#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int k, n;
    cin >> n >> k;
    string s;
    cin >> s;
    int n1 = s.size();
    char s1[n], s2[n], s3[n];
    for (int i = 0; i < k; ++i) {
      if (i % 3 == 0) {
        s1[i] = 'R';
        s2[i] = 'G';
        s3[i] = 'B';
      } else if (i % 3 == 1) {
        s1[i] = 'G';
        s2[i] = 'B';
        s3[i] = 'R';
      } else {
        s1[i] = 'B';
        s2[i] = 'R';
        s3[i] = 'G';
      }
    }
    int min1 = INT_MAX;
    for (int i = 0; i < n - k + 1; ++i) {
      int c = 0;
      for (int j = i; j < i + k; ++j) {
        if (s[j] != s1[j - i]) c++;
      }
      min1 = min(min1, c);
      c = 0;
      for (int j = i; j < i + k; ++j) {
        if (s[j] != s2[j - i]) c++;
      }
      min1 = min(min1, c);
      c = 0;
      for (int j = i; j < i + k; ++j) {
        if (s[j] != s3[j - i]) c++;
      }
      min1 = min(min1, c);
    }
    cout << min1 << "\n";
  }
  return 0;
}
