#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int n, m, d, tot;
int head[100005], nxt[100005], to[100005];
char s[100005][55];
void add_edge(int x, int y) {
  tot++;
  nxt[tot] = head[x], to[tot] = y;
  head[x] = tot;
  return;
}
int idx(int x, int y) {
  if (y == d) y = 0;
  return x * d + y;
}
int dt[5000005], low[5000005], col[5000005], T, scc, top, stk[5000005];
int sc[5000005];
int get_r(int x) { return x / d; }
int get_c(int x) { return x % d; }
int get_val(int x) {
  int r = get_r(x);
  int c = get_c(x);
  return s[r][c] - '0';
}
bool vis[5000005];
inline void tarjan(int x) {
  dt[x] = low[x] = ++T;
  stk[top++] = x;
  int r = get_r(x), c = get_c(x);
  for (int i = head[r]; i; i = nxt[i]) {
    int id = idx(to[i], c + 1);
    if (!dt[id]) {
      tarjan(id);
      low[x] = min(low[x], low[id]);
    } else if (!col[id])
      low[x] = min(low[x], dt[id]);
  }
  if (dt[x] == low[x]) {
    scc++;
    int y;
    vector<int> A;
    do {
      y = stk[--top];
      col[y] = scc;
      A.push_back(y);
    } while (y != x);
    for (auto k : A) {
      int r = get_r(k);
      if (!vis[r] && get_val(k) == 1) {
        vis[r] = 1;
        sc[scc]++;
      }
    }
    for (auto k : A) {
      int r = get_r(k);
      vis[r] = 0;
    }
  }
  return;
}
vector<int> v[5000005];
int dp[5000005];
int dfs(int k) {
  int m = 0;
  for (auto x : v[k]) {
    if (!vis[x]) dfs(x), vis[x] = 1;
    m = max(m, dp[x]);
  }
  dp[k] = m + sc[k];
  return dp[k];
}
int st[100005], fs[100005];
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d %d %d", &n, &m, &d);
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    x--, y--;
    add_edge(x, y);
    st[i] = x, fs[i] = y;
  }
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  tarjan(0);
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < d; j++) {
      int x = idx(st[i], j), y = idx(fs[i], j + 1);
      x = col[x], y = col[y];
      if (!x || !y) continue;
      if (x != y) v[x].push_back(y);
    }
  }
  int ans = dfs(col[0]);
  printf("%d\n", ans);
  return 0;
}
