#include <bits/stdc++.h>
using namespace std;
const long long N = 100011;
int n, m, d, score[N][50], dp[N][50];
vector<pair<int, int> > now, co[N][50], A;
vector<int> g[N], b[N];
string s[N];
bool mark[N][50];
pair<int, int> P, par[N][50];
set<int> second;
void dfs(pair<int, int> v) {
  mark[v.first][v.second] = 1;
  for (int i = 0; i < g[v.first].size(); i++) {
    pair<int, int> u;
    u.first = g[v.first][i];
    u.second = (v.second + 1) % d;
    if (!mark[u.first][u.second]) dfs(u);
  }
  now.push_back(v);
}
void bdfs(pair<int, int> v) {
  if (s[v.first][v.second] == '1') second.insert(v.first);
  mark[v.first][v.second] = 1;
  par[v.first][v.second] = P;
  co[P.first][P.second].push_back(v);
  for (int i = 0; i < b[v.first].size(); i++) {
    pair<int, int> u;
    u.first = b[v.first][i], u.second = (v.second - 1 + d) % d;
    if (!mark[u.first][u.second]) bdfs(u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> v >> u;
    g[v].push_back(u);
    b[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < d; j++)
      if (!mark[i][j]) dfs({i, j});
  memset(mark, 0, sizeof(mark));
  for (int i = now.size() - 1; i >= 0; i--) {
    pair<int, int> v = now[i];
    if (!mark[v.first][v.second]) {
      second.clear();
      P = v;
      bdfs(v);
      score[v.first][v.second] = second.size();
      A.push_back(v);
    }
  }
  for (int i = A.size() - 1; i >= 0; i--) {
    pair<int, int> v = A[i];
    for (int j = 0; j < co[v.first][v.second].size(); j++) {
      pair<int, int> u = co[v.first][v.second][j];
      for (int x = 0; x < g[u.first].size(); x++) {
        pair<int, int> z;
        z.first = g[u.first][x], z.second = (u.second + 1) % d;
        if (par[z.first][z.second] != v)
          dp[v.first][v.second] = max(
              dp[v.first][v.second],
              dp[par[z.first][z.second].first][par[z.first][z.second].second]);
      }
    }
    dp[v.first][v.second] += score[v.first][v.second];
  }
  cout << dp[par[1][0].first][par[1][0].second];
}
