#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, maxd = 55, maxN = 5e6 + 5, maxe = 5e6 + 5;
int n, m, d, num[maxN];
int getid(int i, int j) { return i + n * (j - 1); }
int tot, go[maxe], nxt[maxe], f1[maxN];
void ins(int x, int y) {
  go[++tot] = y;
  nxt[tot] = f1[x];
  f1[x] = tot;
}
int tot2, go2[maxe], nxt2[maxe], f2[maxN], com[maxN];
void ins2(int x, int y) {
  go2[++tot2] = y;
  nxt2[tot2] = f2[x];
  f2[x] = tot2;
  com[y]++;
}
int sum, dfn[maxN], low[maxN], bz[maxN], z0, z[maxN], rt[maxN];
void tarjan(int k) {
  dfn[k] = low[k] = ++sum;
  bz[k] = 1;
  z[++z0] = k;
  for (int p = f1[k]; p; p = nxt[p]) {
    if (!bz[go[p]]) {
      tarjan(go[p]);
      low[k] = min(low[k], low[go[p]]);
    } else if (bz[go[p]] == 1)
      low[k] = min(low[k], dfn[go[p]]);
  }
  if (dfn[k] == low[k]) {
    do {
      bz[z[z0]] = 2;
      rt[z[z0]] = k;
    } while (z[z0--] != k);
  }
}
int f[maxN], q[maxN];
void topo() {
  int j = 0;
  for (int i = 1; i <= n * d; i++)
    if (rt[i] == i && !com[i]) q[++j] = i;
  for (int i = 1; i <= j; i++) {
    f[q[i]] += num[q[i]];
    for (int p = f2[q[i]]; p; p = nxt2[p]) {
      f[go2[p]] = max(f[go2[p]], f[q[i]]);
      if (--com[go2[p]] == 0) q[++j] = go2[p];
    }
  }
}
char s[maxd];
int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    for (int j = 1; j <= d; j++) ins(getid(x, j), getid(y, j % d + 1));
  }
  tarjan(1);
  memset(bz, 0, sizeof(bz));
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= d; j++)
      if (s[j] == '1') {
        int id = rt[getid(i, j)];
        if (!bz[id]) bz[id] = 1, num[id]++;
      }
    for (int j = 1; j <= d; j++) bz[rt[getid(i, j)]] = 0;
  }
  for (int i = 1; i <= n * d; i++)
    for (int p = f1[i]; p; p = nxt[p])
      if (rt[go[p]] != rt[i] && rt[go[p]] && rt[i]) ins2(rt[go[p]], rt[i]);
  topo();
  printf("%d\n", f[1]);
}
