#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int min = k;
    string s, s1 = "", s2 = "", s3 = "";
    cin >> s;
    for (int i = 1; i <= k; i++) {
      if (i % 3 == 1) {
        s1 += 'R';
        s2 += 'G';
        s3 += 'B';
      }
      if (i % 3 == 2) {
        s1 += 'G';
        s2 += 'B';
        s3 += 'R';
      }
      if (i % 3 == 0) {
        s1 += "B";
        s2 += 'R';
        s3 += 'G';
      }
    }
    for (int i = 0; i < n - k + 1; i++) {
      int a = 0, b = 0, c = 0;
      for (int j = i, z = 0; z < k; j++, z++) {
        if (s[j] != s1[z]) a++;
        if (s[j] != s2[z]) b++;
        if (s[j] != s3[z]) c++;
      }
      if (min > a) min = a;
      if (min > b) min = b;
      if (min > c) min = c;
    }
    cout << min << "\n";
    ;
  }
  return 0;
}
