#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<tuple>
using namespace std;
bool mask[25];
string board[5];
int ans;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 5; i++)
cin >> board[i];
fill(mask + 7, mask + 25, true);
do {
queue<pair<int, int>> q;
int dasom = 0;
int adj = 0;
bool isp7[5][5] = {};
bool vis[5][5] = {};
for (int i = 0; i < 25; i++) {
if (!mask[i]) {
int x = i / 5;
int y = i % 5;
isp7[x][y] = true;
if (q.empty()) {
q.push({ x,y });
vis[x][y] = true;
}
}
}
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop();
adj++;
if (board[x][y] == 'S')dasom += 1;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= 5 || ny < 0 || ny >= 5 || !isp7[nx][ny] || vis[nx][ny])continue;
q.push({ nx,ny });
vis[nx][ny] = true;
}
}
if (adj >= 7 && dasom >= 4) {
ans++;
}
} while (next_permutation(mask, mask + 25));
cout << ans;
}