#include<iostream>
#include<vector>
#include<set>
#include<cstdio>
using namespace std;
set<vector<int>> s;
int n,m = 5,ans = 0;
bool isValid(const vector<int>& candidate, const set<vector<int>>& states) {
for (const auto& state : states) {
bool valid = false;
// 检查单拨圈差异
for (int i = 0; i < 5; i) {
for(int a = 1;a <= 9;a){
vector<int> temp = candidate;
temp[i] = (temp[i] + a) % 10;
if (temp == state) { valid = true; break; }
/temp = candidate;
temp[i] = (candidate[i] - a) % 10; // 相当于-1
if (temp == state) { valid = true; break; }/
}
}
if (valid) continue;
}
void dfs(int k,vector<int> ve){
if(k == m + 1){
/for(auto it : ve){
cout << it << " ";
}
cout << endl;/
if(s.count(ve)) return ;
if(isValid(ve,s)) ans++;
return ;
}
for(int i = 0;i <= 9;i++){
ve.push_back(i);
dfs(k + 1,ve);
ve.pop_back();
}
}
int main(){
freopen("lock.in","r",stdin);
freopen("lock.out","w",stdout);
cin >> n;
for(int i = 1;i <= n;i++){
vector<int> ve;
int j = 5;
while(j--){
int x;
cin >> x;
ve.push_back(x);
}
s.insert(ve);
}
dfs(1,{});
/for(auto it : s){
for(auto num : it){
cout << num << " ";
}
cout << endl;
}/
cout << ans;
fclose(stdin);
fclose(stdout);
return 0;
}