#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7, maxm = 5e6 + 7;
struct Node {
  int h[maxm], e[maxm], ne[maxm], cnt;
  void add(int u, int v) {
    e[++cnt] = v;
    ne[cnt] = h[u];
    h[u] = cnt;
  }
} G1, G2;
char s[100010][60];
int sk[maxm], dfn[maxm], low[maxm], clock_dfs;
int dp[maxm], sz[maxm], unicom[maxm], vis[maxm], top, scc;
void tarjan(int u) {
  vis[u] = 1, sk[++top] = u;
  dfn[u] = low[u] = ++clock_dfs;
  for (int i = G1.h[u]; i; i = G1.ne[i]) {
    int v = G1.e[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;
    int t;
    do {
      t = sk[top];
      vis[t] = 0;
      unicom[t] = scc;
      top--;
    } while (t != u);
  }
}
int dfs(int u) {
  if (dp[u]) return dp[u];
  int ans = 0;
  for (int i = G2.h[u]; i; i = G2.ne[i]) {
    int v = G2.e[i];
    ans = max(ans, dfs(v));
  }
  dp[u] = sz[u] + ans;
  return dp[u];
}
void solve() {
  int n, m, d;
  scanf("%d%d%d", &n, &m, &d);
  int tot = n * d;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    for (int j = 0; j < d; j++) {
      G1.add(((u - 1) * d + j + 1), ((v - 1) * d + (j + 1) % d + 1));
    }
  }
  for (int i = 1; i <= n; i++) scanf("%s", s[i]);
  for (int i = 1; i <= tot; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < d; j++) {
      int u = ((i - 1) * d + j + 1);
      if (s[i][j] == '1' && vis[unicom[u]] != i)
        vis[unicom[u]] = i, sz[unicom[u]]++;
      for (int k = G1.h[u]; k; k = G1.ne[k]) {
        int v = G1.e[k];
        if (unicom[u] != unicom[v]) G2.add(unicom[u], unicom[v]);
      }
    }
  }
  cout << dfs(unicom[1]) << endl;
  return;
}
int main() {
  solve();
  return 0;
}
