#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 10;
int Laxt[maxn], Next[maxn], To[maxn], cnt;
int Laxt2[maxn], Next2[maxn], To2[maxn], cnt2;
int d, n, m, dfn[maxn], low[maxn], sk[maxn], vis[maxn];
int sz[maxn], dp[maxn], bel[maxn], Time, scc, top;
char s[100001][51];
void add(int u, int v) {
  Next[++cnt] = Laxt[u];
  Laxt[u] = cnt;
  To[cnt] = v;
}
void add2(int u, int v) {
  Next2[++cnt2] = Laxt2[u];
  Laxt2[u] = cnt2;
  To2[cnt2] = v;
}
int id(int a, int b) { return (a - 1) * d + b + 1; }
void tarjan(int u) {
  dfn[u] = low[u] = ++Time;
  sk[++top] = u;
  vis[u] = 1;
  for (int i = Laxt[u]; i; i = Next[i]) {
    int v = To[i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (vis[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    ++scc;
    do {
      vis[sk[top]] = 0;
      bel[sk[top--]] = scc;
    } while (sk[top + 1] != u);
  }
}
int dfs(int u) {
  if (dp[u]) return dp[u];
  int ans = 0;
  for (int i = Laxt2[u]; i; i = Next2[i]) ans = max(ans, dfs(To2[i]));
  dp[u] = sz[u] + ans;
  return dp[u];
}
int main() {
  int u, v;
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    for (int j = 0; j < d; j++) add(id(u, j), id(v, (j + 1) % d));
  }
  for (int i = 1; i <= n; i++) scanf("%s", s[i]);
  for (int i = 1; i <= n * d; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < d; j++) {
      int x = id(i, j);
      if (s[i][j] == '1' && vis[bel[x]] != i) vis[bel[x]] = i, sz[bel[x]]++;
      for (int k = Laxt[x]; k; k = Next[k]) {
        int v = To[k];
        if (bel[x] != bel[v]) add2(bel[x], bel[v]);
      }
    }
  printf("%d\n", dfs(bel[1]));
}
