#include <bits/stdc++.h>
using namespace std;
long long int fun(long long int n) {
  long long int sum = 0;
  while (n != 0) {
    int a = n % 10;
    sum += a;
    n /= 10;
  }
  return sum;
}
long long int par[100009];
long long int size[100009];
long long int parent(long long int x) {
  if (x == par[x]) return x;
  long long int y = parent(par[x]);
  par[x] = y;
  return y;
}
void union1(long long int a, long long int b) {
  long long int x = parent(a);
  long long int y = parent(b);
  if (x == y) return;
  par[x] = y;
}
void init() {
  for (long long int i = 0; i < 100009; i++) {
    par[i] = i;
  }
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first < b.first);
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long int binarySearch(long long int low, long long int high,
                           long long int key, long long int a[]) {
  long long int mid = low + (high - low) / 2;
  while (low <= high) {
    if (a[mid] < key)
      low = mid + 1;
    else if (a[mid] > key)
      high = mid - 1;
    else
      return mid + 1;
  }
  return -1;
}
long long int stringToDecimal(string s) {
  long long int ans = 0;
  long long int base = 1;
  for (int i = s.length() - 1; i >= 0; i--) {
    ans = ans + (s[i] - '0') * base;
    base = base * 2;
  }
  return ans;
}
long long int powerfun(long long int base, long long int n) {
  if (n == 1) {
    return base;
  }
  if (n % 2 == 0)
    return powerfun(base, n / 2) * powerfun(base, n / 2);
  else
    return powerfun(base, n / 2) * powerfun(base, n / 2) * base;
}
string rev(string s) {
  int x = s.length();
  string r = "";
  for (int i = x - 1; i >= 0; i--) {
    r += s[i];
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    string r[3] = {"", "", ""};
    char c[3] = {'R', 'G', 'B'};
    int x = 0;
    vector<string> v;
    for (int i = 0; i < n - k + 1; i++) {
      string y = s.substr(i, k);
      v.push_back(y);
    }
    int m = v.size();
    int ans = 1000000000;
    int cnt = 0;
    int y = 0;
    for (int i = 0; i < int(m); i++) {
      if (ans == 0) break;
      cnt = 0;
      y = 0;
      for (int j = 0; j < int(k); j++) {
        char z = v[i][j];
        if (z != c[y]) cnt++;
        y++;
        y %= 3;
      }
      ans = min(ans, cnt);
      if (ans == 0) break;
    }
    for (int i = 0; i < int(m); i++) {
      y = 1;
      if (ans == 0) break;
      cnt = 0;
      for (int j = 0; j < int(k); j++) {
        char z = v[i][j];
        if (z != c[y]) cnt++;
        y++;
        y %= 3;
      }
      ans = min(ans, cnt);
    }
    for (int i = 0; i < int(m); i++) {
      y = 2;
      if (ans == 0) break;
      cnt = 0;
      for (int j = 0; j < int(k); j++) {
        char z = v[i][j];
        if (z != c[y]) cnt++;
        y++;
        y %= 3;
      }
      ans = min(ans, cnt);
      if (ans == 0) break;
    }
    cout << ans << '\n';
  }
}
