#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int x, y, n, i, t, k, z, p;
  string s;
  cin >> t;
  while (t--) {
    long long int ans1 = INT_MAX;
    cin >> n >> k;
    cin >> s;
    string s1 = "", s2 = "", s3 = "", s4 = "", s5 = "", s6 = "";
    for (i = 0; i < k / 3; i++) {
      s1 = s1 + "RGB";
    }
    if (k % 3 == 1) s1 = s1 + "R";
    if (k % 3 == 2) s1 = s1 + "RG";
    for (i = 0; i < k / 3; i++) {
      s2 = s2 + "GBR";
    }
    if (k % 3 == 1) s2 = s2 + "G";
    if (k % 3 == 2) s2 = s2 + "GB";
    for (i = 0; i < k / 3; i++) {
      s3 = s3 + "BRG";
    }
    if (k % 3 == 1) s3 = s3 + "B";
    if (k % 3 == 2) s3 = s3 + "BR";
    x = 0, y = 0, z = 0;
    long long int ans = INT_MAX;
    for (i = 0; i < n - k + 1; i++) {
      string s4 = "";
      for (long long int j = i; j < i + k; j++) {
        s4 += s[j];
      }
      x = 0, y = 0, z = 0;
      for (long long int l = 0; l < k; l++) {
        if (s4[l] != s1[l]) x++;
        if (s4[l] != s2[l]) y++;
        if (s4[l] != s3[l]) z++;
      }
      ans = min(x, y);
      ans = min(ans, z);
      ans1 = min(ans1, ans);
    }
    cout << ans1 << " " << endl;
  }
  return 0;
}
