#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, ii;
  cin >> t;
  for (ii = 0; ii < t; ii++) {
    long n, m;
    cin >> n >> m;
    string s, s1, s2, s3;
    cin >> s;
    long l;
    l = s.size();
    s1 = "RGB";
    s2 = "GBR";
    s3 = "BRG";
    long i, mm = 100000000, c, j;
    for (i = 0; i <= l - m; i++) {
      c = 0;
      for (j = i; j < i + m; j++) {
        if (s[j] != s1[j % 3]) c++;
      }
      if (mm > c) mm = c;
      c = 0;
      for (j = i; j < i + m; j++) {
        if (s[j] != s2[j % 3]) c++;
      }
      if (mm > c) mm = c;
      c = 0;
      for (j = i; j < i + m; j++) {
        if (s[j] != s3[j % 3]) c++;
      }
      if (mm > c) mm = c;
    }
    cout << mm << "\n";
  }
  return 0;
}
