#include <bits/stdc++.h>
using namespace std;

#define N 300001
vector<int> a[N];
pair<pair<int, int>, char> b[N];

int main()
{
    int n, x;
    cin >> n;
    int brS = 0, brI = 0, brO = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        int c1 = 2;
        cin >> x >> y;
        cin >> c;
        b[i].first.first = x;
        b[i].first.second = y;
        b[i].second = c;
        if (c == 'S') {
            brS++;
            c1 = 0;
        }
        if (c == 'I') {
            brI++;
            c1 = 1;
        }
        if (c == 'O')
            brO++;
        a[x].push_back(y);
        a[x].push_back(c1);
        a[y].push_back(x);
        a[y].push_back(c1);
    }
    if (brS == 1) {
        for (int i = 0; i < n; i++) {
            if (b[i].second == 'S') {
                int x1, x2, x3, x4;
                int g1 = b[i].first.first, g2 = b[i].first.second;
                for (auto i = a[g1].begin(); i != a[g1].end(); i++) {
                    if (*i == g2) {
                        i++;
                        continue;
                    }
                    for (auto j = a[*i].begin(); j != a[*i].end(); j++) {
                        if (*j == g1) {
                            j++;
                            continue;
                        }
                        j++;
                        x2 = *j;
                        break;
                    }
                    i++;
                    x1 = *i;
                    break;
                }
                for (auto i = a[g2].begin(); i != a[g2].end(); i++) {
                    if (*i == g1) {
                        i++;
                        continue;
                    }
                    for (auto j = a[*i].begin(); j != a[*i].end(); j++) {
                        if (*j == g2) {
                            j++;
                            continue;
                        }
                        j++;
                        x4 = *j;
                        break;
                    }
                    i++;
                    x3 = *i;
                    break;
                }
                int resenje = 0;
                if (x1 != x3)
                    resenje++;
                if (x1 != x2)
                    resenje++;
                if (x3 != x4)
                    resenje++;
                cout << resenje;
                return 0;
            }
        }
    }

    return 0;
}