#include using namespace std; const int MaxN = (int)2e5 + 10; const int INF = (int)1e9; const int MOD = (int)1e9 + 7; void solve() { int n; cin >> n; map timer; int ans = 0; for (int i = 1; i <= n; ++i) { string s; cin >> s; if (timer.count(s)) { ans += timer[s]; continue; } int who[256] = {}; who['d'] = 1; who['f'] = 1; who['j'] = 2; who['k'] = 2; int cur = 0; assert (s.length() <= 20); for (int j = 0; j < (int)s.length(); ++j) { if (j != 0 && who[s[j]] == who[s[j - 1]]) { cur += 4; } else { cur += 2; } } timer[s] = cur / 2; ans += cur; } cout << ans << "\n"; } int main() { // freopen("input.txt", "r", stdin); int t; scanf("%d\n", &t); while (t --> 0) { solve(); } return 0; }