#include <bits/stdc++.h>
int main(void) {
  int count = -1;
  int i, j, k, set;
  int count_exercise = 0;
  while (1) {
    scanf("%d", &count);
    if (count == 0) break;
    char exercise[320] = {};
    set = 0;
    gets(exercise);
    if (count % 2)
      count = 3 * (count - 1);
    else
      count = 3 * (count);
    for (i = 0; i <= count; i += 6) {
      if (count == 0) break;
      if (*(exercise + i + 1) == *(exercise + i + 4) &&
          *(exercise + i) != *(exercise + i + 3))
        count_exercise++;
    }
    count_exercise = 0;
    if (set != 0) printf("%d", count_exercise);
    set++;
  }
  return 0;
}
