#include <bits/stdc++.h>
using namespace std;
long long int diff(string s1, string s2) {
  long long int cnt = 0;
  for (long long int i = 0; i < s1.length(); i++) {
    if (s1[i] != s2[i]) cnt++;
  }
  return cnt;
}
void solve() {
  long long int q, x, y, a, b, c, d;
  cin >> q;
  while (q--) {
    long long int n, k;
    cin >> n >> k;
    string str;
    string s1 = "", s2 = "", s3 = "";
    cin >> str;
    for (long long int i = 0; i < k; i++) {
      if (i % 3 == 0)
        s1 += 'R';
      else if (i % 3 == 1)
        s1 += 'G';
      else
        s1 += 'B';
    }
    for (long long int i = 0; i < k; i++) {
      if (i % 3 == 0)
        s2 += 'G';
      else if (i % 3 == 1)
        s2 += 'B';
      else
        s2 += 'R';
    }
    for (long long int i = 0; i < k; i++) {
      if (i % 3 == 0)
        s3 += 'B';
      else if (i % 3 == 1)
        s3 += 'R';
      else
        s3 += 'G';
    }
    long long int ans = (long long int)(1e18);
    string s4;
    for (long long int i = 0; i <= str.length() - k; i++) {
      s4 = str.substr(i, k);
      ans = min(ans, diff(s1, s4));
      ans = min(ans, diff(s2, s4));
      ans = min(ans, diff(s3, s4));
      if (ans == 0) break;
    }
    cout << ans << '\n';
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
