#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int sum = k;
    char c[] = {'R', 'G', 'B'};
    for (int i = 0; i <= n - k; i++) {
      for (int l = 0; l < 3; l++) {
        int ans = 0;
        int h = l;
        for (int j = 0; j < k; j++) {
          if (s[i + j] != c[h % 3]) ans++;
          h++;
        }
        sum = min(sum, ans);
      }
    }
    cout << sum << "\n";
  }
}
