#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &k) {
  k = 0;
  int flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    k = k * 10 + c - '0';
    c = getchar();
  }
  k *= flag;
}
const int N = 5000005;
struct node {
  int y, next;
} b[N];
struct node1 {
  int x, y;
} b1[100005];
int n, m, k, s, t, head[N], tot, tot1, d, l, r, ans, x, y;
int dfn[N], low[N], sta[N], top, dfs_num, col[N], col_num;
int g[N], f[N], h[N];
char c[55];
bitset<55> u[100005];
queue<int> q;
inline void add(int s, int t) {
  b[++tot].y = t;
  b[tot].next = head[s];
  head[s] = tot;
}
inline void add1(int s, int t) {
  if (col[s] && col[t] && col[s] != col[t]) {
    add(col[s], col[t]);
    h[col[t]]++;
  }
}
inline void tarjan(int x) {
  dfn[x] = low[x] = ++dfs_num;
  sta[++top] = x;
  f[x] = 1;
  int y;
  for (int k = head[x]; k; k = b[k].next) {
    y = b[k].y;
    if (!dfn[y]) {
      tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (f[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (low[x] == dfn[x]) {
    ++col_num;
    for (; sta[top + 1] != x; --top) {
      col[sta[top]] = col_num;
      f[sta[top]] = 0;
      if (sta[top] % d == 0) {
        l = sta[top] / d;
        r = d;
      } else {
        l = sta[top] / d + 1;
        r = sta[top] % d;
      }
      if (u[l][r] && h[l] != col_num) {
        h[l] = col_num;
        g[col_num]++;
      }
    }
  }
}
int main() {
  read(n);
  read(m);
  read(d);
  for (int i = 1; i <= m; ++i) {
    read(s);
    read(t);
    b1[i].x = s;
    b1[i].y = t;
    for (int j = 1; j <= d; ++j) add((s - 1) * d + j, (t - 1) * d + j % d + 1);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%s", c + 1);
    for (int j = 1; j <= d; ++j)
      if (c[j] == '1') u[i][j] = 1;
  }
  tarjan(1);
  memset(head, 0, sizeof(head));
  memset(h, 0, sizeof(h));
  tot = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= d; ++j) {
      s = b1[i].x;
      t = b1[i].y;
      add1((s - 1) * d + j, (t - 1) * d + j % d + 1);
    }
  }
  q.push(col[1]);
  int k;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    f[x] += g[x];
    ans = max(ans, f[x]);
    for (k = head[x]; k; k = b[k].next) {
      y = b[k].y;
      f[y] = max(f[y], f[x]);
      if (--h[y] == 0) q.push(y);
    }
  }
  cout << ans << endl;
}
