#include <bits/stdc++.h>
using namespace std;
vector<bool> prime(1000000000 + 5, true);
void SieveOfEratosthenes(long long int n) {
  prime[0] = false;
  prime[1] = false;
  for (long long unsigned int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long unsigned int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
int findFirst(const std::vector<int> &array, int key, int low, int high) {
  int ans = -1;
  while (low <= high) {
    int mid = low + (high - low) / 2;
    if (key == array[mid]) {
      ans = mid;
      high = mid - 1;
    } else if (key > array[mid])
      low = mid + 1;
    else
      high = mid - 1;
  }
  return ans;
}
int findLast(const std::vector<int> &array, int key, int low, int high) {
  int ans = -1;
  while (low <= high) {
    int mid = low + (high - low) / 2;
    if (key == array[mid]) {
      ans = mid;
      low = mid + 1;
    } else if (key > array[mid])
      low = mid + 1;
    else
      high = mid - 1;
  }
  return ans;
}
int d, x, y;
void extendedEuclid(int a, int b) {
  if (b == 0) {
    d = 1;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(b, a % b);
    int temp = x;
    x = y;
    y = temp - (a / b) * y;
  }
}
const int N = 2 * (2e5 + 5);
vector<int> adj[N];
vector<int> level(N, 0);
vector<bool> vis(N, 0);
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  for (int tc = 0; tc < t; tc++) {
    int n, k;
    cin >> n >> k;
    string str, temp;
    cin >> str;
    vector<string> arr;
    set<string> st;
    int d = 5 * n;
    while (d--) {
      temp += "RGB";
    }
    for (int i = 0; i + k < 15 * n; i++) {
      string sub = temp.substr(i, k);
      if (!st.count(sub)) {
        arr.push_back(sub);
        st.insert(sub);
      } else {
        break;
      }
    }
    int mn = 100000;
    for (int i = 0; i < arr.size(); i++) {
      string ss = arr[i];
      for (int i1 = 0; i1 <= n - k; i1++) {
        int cnt = 0;
        for (int j = 0; j < k; j++) {
          if (str[i1 + j] != ss[j]) {
            cnt++;
          }
        }
        mn = min(mn, cnt);
      }
    }
    cout << mn << endl;
  }
  return 0;
}
