#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    string s, s1, s2, s3;
    cin >> s;
    char c = 'R';
    for (int i = 0; i < m; i++) {
      s1.push_back(c);
      if (c == 'R')
        c = 'G';
      else if (c == 'G')
        c = 'B';
      else if (c == 'B')
        c = 'R';
    }
    c = 'G';
    for (int i = 0; i < m; i++) {
      s2.push_back(c);
      if (c == 'R')
        c = 'G';
      else if (c == 'G')
        c = 'B';
      else if (c == 'B')
        c = 'R';
    }
    c = 'B';
    for (int i = 0; i < m; i++) {
      s3.push_back(c);
      if (c == 'R')
        c = 'G';
      else if (c == 'G')
        c = 'B';
      else if (c == 'B')
        c = 'R';
    }
    int mn = 3000000;
    for (int i = 0; i < n - m + 1; i++) {
      int a = 0, b = 0, c = 0;
      for (int j = 0; j < m; j++) {
        if (s[i + j] != s1[j]) a++;
        if (s[i + j] != s2[j]) b++;
        if (s[i + j] != s3[j]) c++;
      }
      mn = min(mn, min(a, min(b, c)));
    }
    cout << mn << endl;
  }
}
