#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<char> str;
    str.push_back('R');
    str.push_back('G');
    str.push_back('B');
    int index;
    int ans = 1e5;
    for (int i = 0; i <= n - k; i++) {
      int swaps = 0;
      index = 0;
      for (int j = i; j < i + k; j++) {
        if (s[j] != str[index]) swaps++;
        index++;
        index %= 3;
      }
      ans = min(ans, swaps);
      swaps = 0;
      index = 1;
      for (int j = i; j < i + k; j++) {
        if (s[j] != str[index]) swaps++;
        index++;
        index %= 3;
      }
      ans = min(ans, swaps);
      swaps = 0;
      index = 2;
      for (int j = i; j < i + k; j++) {
        if (s[j] != str[index]) swaps++;
        index++;
        index %= 3;
      }
      ans = min(ans, swaps);
    }
    cout << ans << "\n";
  }
  return 0;
}
