#include <bits/stdc++.h>
using namespace std;
const int M = 5e6 + 5;
struct NODE {
  int to, nxt;
};
NODE a1[M], a2[M];
int head1[M], head2[M];
char str[100005][55];
int dfn[M], low[M];
int ty[M], cnt[M], in[M];
bool vis[M];
int n, m, d, num1, num2, x, o;
class STACK {
 public:
  STACK() { t = 0; }
  void push(int u) { a[++t] = u; }
  int top() { return a[t]; }
  void pop() { t--; }

 private:
  int t;
  int a[M];
};
STACK st;
int q[M];
int si;
void build(int fr, int to, bool flag) {
  if (flag) {
    a1[num1].to = to;
    a1[num1].nxt = head1[fr];
    head1[fr] = num1++;
  } else {
    a2[num2].to = to;
    a2[num2].nxt = head2[fr];
    head2[fr] = num2++;
  }
}
inline void tarjan(int u) {
  o++;
  dfn[u] = o;
  low[u] = o;
  vis[u] = true;
  st.push(u);
  for (int i = head1[u]; i != -1; i = a1[i].nxt) {
    int v = a1[i].to;
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[v], low[u]);
    } else if (vis[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    x++;
    int tmp;
    do {
      tmp = st.top();
      st.pop();
      ty[tmp] = x;
      int r = tmp / d, c = tmp % d;
      if (in[r] != x && str[r][c] == '1') {
        cnt[x]++;
        in[r] = x;
      }
      vis[tmp] = false;
    } while (tmp != u);
  }
}
void solve() {
  memset(head1, -1, sizeof(head1));
  memset(head2, -1, sizeof(head2));
  memset(cnt, 0, sizeof(cnt));
  memset(dfn, 0, sizeof(dfn));
  memset(vis, false, sizeof(vis));
  scanf("%d%d%d", &n, &m, &d);
  num1 = 0;
  num2 = 0;
  for (int i = 0; i <= m - 1; i++) {
    int fr, to;
    scanf("%d%d", &fr, &to);
    for (int j = 0; j <= d - 1; j++)
      build((fr - 1) * d + j, (to - 1) * d + (j + 1) % d, true);
  }
  for (int i = 0; i <= n - 1; i++) scanf("%s", str[i]);
  o = 0;
  x = 0;
  tarjan(0);
  for (int i = 0; i <= n * d - 1; i++) {
    if (ty[i]) {
      for (int j = head1[i]; j != -1; j = a1[j].nxt) {
        int v = a1[j].to;
        if (ty[i] != ty[v]) build(ty[i], ty[v], false);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= x; i++) {
    int ma = 0;
    for (int j = head2[i]; j != -1; j = a2[j].nxt) ma = max(ma, cnt[a2[j].to]);
    cnt[i] += ma;
  }
  printf("%d\n", cnt[x]);
}
int main() {
  solve();
  return 0;
}
