#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 1000005;
bool DEBUG = true;
int i, j, d, maxx, perm[9], tab[11][11], bat[11][11], dist[11][11], u, pre;
ii pers[9];
string s;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
bool ok(int a, int b) {
return a >=0 && a <= 10 && b >=0 && b <= 10;
}
void spread(int u) {
queue<ii> q;
for (int i=0;i<11;i++) for (int j=0;j<11;j++) if (bat[i][j]) {
q.push(ii(i, j));
dist[i][j] = 0;
} else dist[i][j] = -1;
while (!q.empty()) {
ii w = q.front();
q.pop();
for (int k=0;k<4;k++) if (ok(w.first + dx[k], w.second + dy[k]) && dist[w.first + dx[k]][w.second + dy[k]] == -1) {
q.push(ii(w.first + dx[k], w.second + dy[k]));
dist[w.first + dx[k]][w.second + dy[k]] = dist[w.first][w.second] + 1;
}
}
for (int i=0;i<11;i++) for (int j=0;j<11;j++) bat[i][j] = dist[i][j] <= u;
}
bool canLeft(int x, int y) {
int d = 0;
while (x > 0) {
x--;
d++;
for (int i=max(0, y - d);i<=min(10, y + d);i++) if (bat[x][i]) return false;
}
return true;
}
bool canRight(int x, int y) {
int d = 0;
while (x < 10) {
x++;
d++;
for (int i=max(0, y - d);i<=min(10, y + d);i++) if (bat[x][i]) return false;
}
return true;
}
bool canUp(int x, int y) {
int d = 0;
while (y > 0) {
y--;
d++;
for (int i=max(0, x - d);i<=min(10, x + d);i++) if (bat[i][y]) return false;
}
return true;
}
bool canDown(int x, int y) {
int d = 0;
while (y < 10) {
y++;
d++;
for (int i=max(0, x - d);i<=min(10, x + d);i++) if (bat[i][y]) return false;
}
return true;
}
int tim(int ind) {
int x = pers[ind].first;
int y = pers[ind].second;
if (bat[x][y]) return INF;
int res = INF;
if (x + 1 < res && canLeft(x, y)) res = x + 1;
if (11 - x < res && canRight(x, y)) res = 11 - x;
if (y + 1 < res && canUp(x, y)) res = y + 1;
if (11 - y < res && canDown(x, y)) res = 11 - y;
return res;
}
int get() {
for (int i=0;i<11;i++) for (int j=0;j<11;j++) bat[i][j] = tab[i][j];
for (int i=0;i<9;i++) {
int u = tim(perm[i]);
if (u == INF) return i;
spread(u);
/*if (DEBUG) {
cout << u << endl;
for (int j=0;j<11;j++) {
for (int k=0;k<11;k++) cout << dist[j][k];
cout << endl;
}
}*/
}
return 9;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
d = 0;
for (i=0;i<11;i++) for (j=0;j<11;j++) {
cin >> s;
if (s[0] == 'F') tab[i][j] = 1; else if (s[0] == 'P') pers[d++] = ii(i, j);
}
maxx = 0;
for (i=0;i<9;i++) perm[i] = i;
u = 0;
pre = -1;
do {
if (perm[u] == pre) continue;
u = get();
pre = perm[u];
maxx = max(maxx, u);
} while (maxx < 9 && next_permutation(perm, perm + 9));
cout << maxx << endl;
return 0;
}