#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int N = 1e6 + 7;
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int n, k;
    cin >> n >> k;
    int a[n];
    string s;
    cin >> s;
    for (long long i = 0; i < (int)n; i++) {
      if (s[i] == 'R') a[i] = 0;
      if (s[i] == 'G') a[i] = 1;
      if (s[i] == 'B') a[i] = 2;
    }
    int ans = INT_MAX;
    for (long long i = 0; i < (int)n; i++) {
      if (i + k <= n) {
        int cnt1 = 0, cnt2 = 1, cnt3 = 2;
        int res1 = 0, res2 = 0, res3 = 0;
        for (long long j = i; j < (int)i + k; j++) {
          if (a[j] != cnt1 % 3) res1++;
          if (a[j] != cnt2 % 3) res2++;
          if (a[j] != cnt3 % 3) res3++;
          cnt1++, cnt2++, cnt3++;
        }
        ans = min({ans, res1, res2, res3});
      }
    }
    cout << ans << endl;
  }
  return 0;
}
