#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
const int MAX_N = 1e5, D = 50;
vector<int> g[MAX_N], rg[MAX_N];
int n, m, d, comp[D][MAX_N], curr, used[MAX_N], usedd[D][MAX_N];
int c[MAX_N * D];
pair<int, int> p[MAX_N * D];
string s[MAX_N];
vector<pair<int, int>> topsort;
void calc(int day, int u, int &mx) {
  usedd[day][u] = 1;
  for (auto vv : g[u]) {
    int dd = (day + 1) % d;
    if (comp[dd][vv] == comp[day][u] && !usedd[dd][vv]) {
      calc(dd, vv, mx);
    } else {
      mx = max(mx,
               (c[comp[dd][vv]] < 0 ? -c[comp[dd][vv]] : 0) + c[comp[day][u]]);
    }
  }
}
void dfs(int day, int u) {
  comp[day][u] = 1;
  for (auto vv : g[u]) {
    int dd = (day + 1) % d;
    if (!comp[dd][vv]) dfs(dd, vv);
  }
  topsort.push_back({day, u});
}
void sex(int day, int u) {
  if (s[u][day] == '1' && used[u] != curr) {
    c[curr]++;
    used[u] = curr;
  }
  comp[day][u] = curr;
  for (auto vv : rg[u]) {
    int dd = (day == 0 ? d - 1 : day - 1);
    if (!comp[dd][vv]) sex(dd, vv);
  }
}
void $main() {
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v, u--, v--;
    g[u].push_back(v);
    rg[v].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int day = 0; day < d; day++) {
    for (int i = 0; i < n; i++) {
      if (!comp[day][i]) {
        dfs(day, i);
      }
    }
  }
  for (int d = 0; d < D; d++)
    for (int i = 0; i < MAX_N; i++) comp[d][i] = 0;
  reverse(topsort.begin(), topsort.end());
  for (auto [d, u] : topsort) {
    if (!comp[d][u]) {
      ++curr;
      sex(d, u);
      p[curr] = {d, u};
    }
  }
  int ans = 0;
  for (auto id = curr; id >= 1; id--) {
    int mx = c[id];
    calc(p[id].first, p[id].second, mx);
    c[id] = -mx;
    if (id == comp[0][0]) {
      ans = max(ans, mx);
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  $main();
  return 0;
}
