#include <bits/stdc++.h>
using namespace std;
char S[200010];
long long T, n, K, ans;
string s;
inline long long read() {
  long long x = 0, tmp = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') tmp = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return tmp * x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  long long y = 10, len = 1;
  while (y <= x) {
    y = (y << 3) + (y << 1);
    len++;
  }
  while (len--) {
    y /= 10;
    putchar(x / y + 48);
    x %= y;
  }
}
int main() {
  T = read();
  for (long long i = 1; i <= 200000; i++) {
    switch (i % 3) {
      case 1: {
        s += 'R';
        break;
      }
      case 2: {
        s += 'G';
        break;
      }
      case 0: {
        s += 'B';
        break;
      }
    }
  }
  while (T--) {
    n = read();
    K = read();
    ans = 2147483647;
    scanf("%s", S + 1);
    for (long long i = 1; i + K - 1 <= n; i++) {
      for (long long k = 0; k <= 2; k++) {
        long long sum = 0;
        for (long long j = 0; j < K; j++) {
          if (S[i + j] != s[j + k]) sum++;
        }
        ans = min(ans, sum);
      }
    }
    write(ans);
    putchar('\n');
  }
  return 0;
}
