#include <bits/stdc++.h>
int main(void) {
  int count = -1;
  int i, j, k;
  int count_exercise = 0;
  while (scanf("%d", &count), count) {
    char exercise[320] = {};
    gets(exercise);
    count = 6 * (count - 1);
    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++;
    }
    if (count_exercise != 0 && count != 1) printf("%d\n", count_exercise);
    count_exercise = 0;
  }
  return 0;
}
