#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, i, j, sizeStr, count, n, k, minError, kvalue, m, errorCount;
  string s, rgb = "RGB";
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> n >> kvalue;
    cin >> s;
    minError = INT_MAX;
    sizeStr = n + 1;
    for (k = 0; k < sizeStr - kvalue; k++) {
      for (j = 0; j < 3; j++) {
        count = j;
        errorCount = 0;
        for (m = k; m < k + kvalue; m++) {
          if (rgb.compare(count % 3, 1, s, m, 1) != 0) {
            errorCount += 1;
          }
          count += 1;
        }
        if (errorCount < minError) {
          minError = errorCount;
        }
      }
    }
    cout << minError << endl;
  }
}
