#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000005;
const int maxm = 100005;
int n, m, d, x[maxm], y[maxm], deg[maxn], head[maxn], to[maxn], nxt[maxn], tot;
char s[maxm][60];
int low[maxn], dfn[maxn], sta[maxn], col[maxn], len[maxn], f[maxn], top, tim,
    color;
bool vis[maxn], used[maxm];
inline void addedge(int x, int y) {
  to[++tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
inline void tarjan(int u) {
  low[u] = dfn[u] = ++tim, vis[u] = 1, sta[++top] = u;
  for (int i = head[u], v; i; i = nxt[i]) {
    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]) {
    color++;
    int x, y, _top = top;
    do {
      x = (sta[top] - 1) % n + 1, y = (sta[top] - 1) / n;
      if (s[x][y] == '1' && !used[x]) len[color]++, used[x] = 1;
      col[sta[top]] = color;
      vis[sta[top]] = 0;
    } while (sta[top--] != u);
    for (int i = top + 1; i <= _top; i++) used[(sta[i] - 1) % n + 1] = 0;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &d);
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    for (int j = 0; j < d; j++) addedge(x[i] + j * n, y[i] + ((j + 1) % d) * n);
  }
  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 * d; i++) head[i] = 0;
  tot = 0;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < d; j++) {
      u = x[i] + j * n, v = y[i] + ((j + 1) % d) * n;
      if (col[u] != col[v]) addedge(col[v], col[u]), deg[col[u]]++;
    }
  queue<int> q;
  for (int i = 1; i <= color; i++)
    if (!deg[i]) q.push(i);
  while (!q.empty()) {
    u = q.front(), q.pop();
    f[u] += len[u];
    for (int i = head[u]; i; i = nxt[i]) {
      v = to[i];
      if (!--deg[v]) q.push(v);
      f[v] = max(f[v], f[u]);
    }
  }
  printf("%d\n", f[col[1]]);
  return 0;
}
