#include <bits/stdc++.h>
int min_(int x, int y) { return x < y ? x : y; }
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n, k, i, j, min = 100000, count1, count2, count3, index;
    char s[2000];
    char c1[] = {'R', 'G', 'B'};
    char c2[] = {'G', 'B', 'R'};
    char c3[] = {'B', 'R', 'G'};
    scanf("%d %d", &n, &k);
    scanf("%s", s);
    for (i = 0; i < n - k + 1; ++i) {
      count1 = 0;
      count2 = 0;
      count3 = 0;
      index = 0;
      for (j = i; j < k + i; ++j) {
        if (s[j] != c1[index % 3]) {
          count1++;
        }
        if (s[j] != c2[index % 3]) {
          count2++;
        }
        if (s[j] != c3[index % 3]) {
          count3++;
        }
        index++;
      }
      min = min_(count3, min_(count2, min_(min, count1)));
    }
    printf("%d\n", min);
  }
}
