#include <string>
#include <vector>
#include <iostream>
#include <unordered_set>
using namespace std;
inline int hashing(string s) {
return int(s[0] - 'A') * 26 * 26 * 26 + int(s[1] - 'A') * 26 * 26 + int(s[2] - 'A') * 26 + int(s[3] - 'A');
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<int> > gl(676), gr(676), gu(676), gd(676);
vector<string> s(N);
vector<bool> st(676 * 676);
for (int i = 0; i < N; ++i) {
string sa, sb;
cin >> sa >> sb;
s[i] = sa + sb;
int cu = int(s[i][0] - 'A') * 26 + int(s[i][1] - 'A');
int cd = int(s[i][2] - 'A') * 26 + int(s[i][3] - 'A');
int cl = int(s[i][0] - 'A') * 26 + int(s[i][2] - 'A');
int cr = int(s[i][1] - 'A') * 26 + int(s[i][3] - 'A');
gu[cu].push_back(cd);
gd[cd].push_back(cu);
gl[cl].push_back(cr);
gr[cr].push_back(cl);
st[hashing(s[i])] = true;
}
int ans = 0;
for (int i = 0; i < 676; ++i) {
vector<int> va = gl[i], vb = gr[i];
ans += va.size() * vb.size();
vector<bool> fa(676), fb(676);
for (int j : va) fa[j] = true;
for (int j : vb) fb[j] = true;
if (fa[i] && fb[i]) --ans;
}
for (int i = 0; i < 676; ++i) {
vector<int> va = gu[i], vb = gd[i];
ans += va.size() * vb.size();
vector<bool> fa(676), fb(676);
for (int j : va) fa[j] = true;
for (int j : vb) fb[j] = true;
if (fa[i] && fb[i]) --ans;
}
int twos = 0, fours = 0;
for (int i = 0; i < N; ++i) {
string opp1 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp2 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][3]) + string(1, s[i][2]);
if (s[i] != opp1 && st[hashing(opp1)]) ++twos;
if (s[i] != opp2 && st[hashing(opp2)]) ++twos;
if (s[i][1] == s[i][2]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, c) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][3]) + string(1, c);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, s[i][1]) + string(1, c) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, c) + string(1, s[i][2]);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3] && s[i][1] == s[i][2]) {
string opp5 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
if (s[i] != opp5 && st[hashing(opp5)]) ++fours;
}
}
twos /= 2;
fours /= 2;
cout << ans - twos + fours * 3 << endl;
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW5saW5lIGludCBoYXNoaW5nKHN0cmluZyBzKSB7CglyZXR1cm4gaW50KHNbMF0gLSAnQScpICogMjYgKiAyNiAqIDI2ICsgaW50KHNbMV0gLSAnQScpICogMjYgKiAyNiArIGludChzWzJdIC0gJ0EnKSAqIDI2ICsgaW50KHNbM10gLSAnQScpOwp9CmludCBtYWluKCkgewoJY2luLnRpZSgwKTsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoJaW50IE47CgljaW4gPj4gTjsKCXZlY3Rvcjx2ZWN0b3I8aW50PiA+IGdsKDY3NiksIGdyKDY3NiksIGd1KDY3NiksIGdkKDY3Nik7Cgl2ZWN0b3I8c3RyaW5nPiBzKE4pOwoJdmVjdG9yPGJvb2w+I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