#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long int q, n, k;
  cin >> q;
  while (q--) {
    cin >> n >> k;
    string s;
    cin >> s;
    long long int len = s.length();
    long long int dp[len][len][3], ans = 1e18;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < len; i++) {
      for (int j = i; j < len; j++) {
        if (i == j) {
          dp[i][i][0] = !(s[i] == 'R');
          dp[i][i][1] = !(s[i] == 'G');
          dp[i][i][2] = !(s[i] == 'B');
        } else {
          dp[i][j][0] = !(s[j] == 'R') + dp[i][j - 1][2];
          dp[i][j][1] = !(s[j] == 'G') + dp[i][j - 1][0];
          dp[i][j][2] = !(s[j] == 'B') + dp[i][j - 1][1];
        }
        if (j - i + 1 == k) {
          ans = min(ans, dp[i][j][0]);
          ans = min(ans, dp[i][j][1]);
          ans = min(ans, dp[i][j][2]);
        }
      }
    }
    cout << ans << endl;
  }
}
