#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 10, mod = 998244353, M = 1e5 + 5;
template <class o>
inline void qr(o &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + 48);
}
template <class o>
void pr1(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  puts("");
}
inline int ksm(int a, int b = mod - 2) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
inline int add(int a, int b) { return a += b, a >= mod ? a - mod : a; }
inline int sub(int a, int b) { return a -= b, a < 0 ? a + mod : a; }
struct edge {
  int y, next;
} a[N], b[N];
int len, tot, last[N], fir[N];
;
void ins(int x, int y) {
  a[++len] = (edge){y, last[x]};
  last[x] = len;
}
void insert(int x, int y) {
  b[++tot] = (edge){y, fir[x]};
  fir[x] = tot;
}
bool vis[N];
int sta[N], top, dfn[N], low[N], cnt, w[N];
char str[M][55];
int n, m, d, v[N];
int bel[N];
int tmp;
inline void tarjan(int x) {
  dfn[x] = low[x] = ++tmp;
  sta[++top] = x;
  vis[x] = 1;
  for (int k = last[x], y; k; k = a[k].next) {
    if (!dfn[y = a[k].y]) {
      tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (vis[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (low[x] == dfn[x]) {
    ++cnt;
    do {
      vis[sta[top]] = 0;
      bel[sta[top]] = cnt;
      int i = sta[top] / d, j = sta[top] % d;
      if (str[i][j] == '1' && v[i] != cnt) v[i] = cnt, ++w[cnt];
    } while (sta[top--] != x);
  }
}
void solve() {
  qr(n), qr(m), qr(d);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    qr(x), qr(y);
    for (int j = 0; j <= d - 1; ++j) {
      ins((x - 1) * d + j, (y - 1) * d + (j + 1) % d);
    }
  }
  for (int i = 0; i <= n - 1; ++i) scanf("%s", str[i]);
  tarjan(0);
  for (int x = 0; x <= n * d - 1; ++x) {
    if (bel[x]) {
      for (int k = last[x], y; k; k = a[k].next)
        if (bel[y = a[k].y] != bel[x]) insert(bel[x], bel[y]);
    }
  }
  for (int x = 1; x <= cnt; ++x) {
    int sum = 0;
    for (int k = fir[x], y; k; k = b[k].next) {
      sum = max(sum, w[y = b[k].y]);
    }
    w[x] += sum;
  }
  pr2(w[cnt]);
}
int main() {
  solve();
  return 0;
}
