#include <bits/stdc++.h>
using namespace std;
int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || '9' < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f * x;
}
struct graph {
  struct Edge {
    int v, nxt;
  } edge[5000000 + 5];
  int ecnt, head[5000000 + 5];
  void Addedge(int u, int v) {
    edge[++ecnt] = (Edge){v, head[u]}, head[u] = ecnt;
    return;
  }
} Graph, Scc;
int n, m, d;
int tp, S[5000000 + 5];
int cnt_scc, scc[5000000 + 5];
int ncnt, dfn[5000000 + 5], low[5000000 + 5];
void Trajan(int u) {
  S[++tp] = u;
  dfn[u] = low[u] = ++ncnt;
  for (int i = Graph.head[u]; i; i = Graph.edge[i].nxt) {
    int v = Graph.edge[i].v;
    if (dfn[v]) {
      if (!scc[v]) low[u] = min(low[u], dfn[v]);
      continue;
    }
    Trajan(v);
    low[u] = min(low[u], low[v]);
  }
  if (low[u] == dfn[u]) {
    cnt_scc++;
    int x;
    do {
      x = S[tp--];
      scc[x] = cnt_scc;
    } while (x != u);
  }
  return;
}
int have[5000000 + 5], val[5000000 + 5], f[5000000 + 5], de[5000000 + 5];
void Topological() {
  queue<int> Q;
  for (int i = 1; i <= cnt_scc; i++)
    if (!de[i]) Q.push(i), f[i] = val[i];
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = Scc.head[u]; i; i = Scc.edge[i].nxt) {
      int v = Scc.edge[i].v;
      de[v]--;
      f[v] = max(f[v], f[u] + val[v]);
      if (!de[v]) Q.push(v);
    }
  }
  return;
}
char str[100];
int main() {
  n = read(), m = read(), d = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    for (int j = 1; j <= d; j++) Graph.Addedge(u + (j - 1) * n, v + j % d * n);
  }
  for (int i = 1; i <= d * n; i++)
    if (!dfn[i]) Trajan(i);
  for (int u = 1; u <= d * n; u++)
    for (int i = Graph.head[u]; i; i = Graph.edge[i].nxt) {
      int v = Graph.edge[i].v;
      if (scc[u] != scc[v]) {
        Scc.Addedge(scc[v], scc[u]), de[scc[u]]++;
      }
    }
  for (int u = 1; u <= n; u++) {
    scanf("%s", str + 1);
    for (int i = 1; i <= d; i++)
      if (str[i] == '1' && have[scc[u + (i - 1) * n]] != u)
        have[scc[u + (i - 1) * n]] = u, val[scc[u + (i - 1) * n]]++;
  }
  Topological();
  printf("%d\n", f[scc[1]]);
  return 0;
}
