#include <bits/stdc++.h>
using namespace std;
int n, m, d, id[100005], cnt, ord[100005], ocnt, g[100005], gg[55][55],
    gs[100005], own[100005][55], add[100005][55], ad[55], addd[55][55],
    sub[55][55], at, gi, ag, mg, gc, dd[100005], ngi, nag;
vector<int> va[100005], vb[100005];
char x[100005][55];
bool v[100005], vvv[100005];
int ta, tb;
void dfs1(int a) {
  v[a] = 1;
  for (int i : va[a])
    if (!v[i]) dfs1(i);
  ord[ocnt++] = a;
}
void dfs2(int a) {
  v[a] = 0;
  id[a] = cnt;
  for (int i : vb[a])
    if (v[i]) dfs2(i);
}
void dfs3(int a) {
  vvv[a] = 1;
  for (int i : va[a])
    if (id[a] == id[i])
      if (!vvv[i]) {
        dd[i] = dd[a] + 1;
        dfs3(i);
      } else
        gc = gg[gc][abs(dd[a] + 1 - dd[i]) % gc];
}
int gcd(int a, int b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i <= d; i++)
    for (int j = 0; j <= d; j++) {
      gg[i][j] = gcd(i, j);
      addd[i][j] = (i + j) % d;
      sub[i][j] = (i + d - j) % d;
    }
  while (m--) {
    scanf("%d%d", &ta, &tb);
    va[ta].push_back(tb);
    vb[tb].push_back(ta);
  }
  for (int i = 1; i <= n; i++) scanf("%s", x[i]);
  dfs1(1);
  for (int i = ocnt - 1; i >= 0; i--)
    if (v[ord[i]]) {
      cnt++;
      dfs2(ord[i]);
      gc = d;
      dfs3(ord[i]);
      g[cnt] = gc;
    }
  for (int i = 1; i <= n; i++)
    if (id[i]) gs[i] = dd[i] % g[id[i]];
  for (int i = 0; i < n; i++) {
    at = ord[i];
    gi = id[at];
    ag = g[gi];
    mg = gs[at];
    for (int j = 0; j < ag; j++)
      for (int k = j; k < d; k += ag)
        if (x[at][k] == '1') {
          own[gi][sub[j][mg] % ag]++;
          break;
        }
    for (int j : va[at]) {
      ngi = id[j];
      if (gi != ngi) {
        nag = g[ngi];
        gc = gg[ag][nag];
        for (int k = 0; k < gc; k++) {
          ad[k] = 0;
          for (int l = k; l < nag; l += gc)
            ad[k] = max(ad[k], own[ngi][l] + add[ngi][l]);
        }
        for (int k = 0; k < ag; k++)
          add[gi][k] = max(add[gi][k], ad[sub[addd[k + 1][mg]][gs[j]] % gc]);
      }
    }
  }
  printf("%d\n", own[1][0] + add[1][0]);
  return 0;
}
