#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int d;
bool mo[100005][55];
int dfn[100005];
int low[100005];
int sta[100005];
bool inst[100005];
int nTop;
int link_head[100005];
vector<int> link[100005];
vector<int> e[100005];
int q[55 * 100005];
int dp[100005][55];
bool ok[100005][55] = {};
int ti;
int gcd(int a, int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
void dfs_cl(int u) {
  ++ti;
  dfn[u] = ti;
  low[u] = ti;
  sta[nTop++] = u;
  inst[u] = true;
  int i;
  for (i = 0; i < e[u].size(); i++) {
    if (dfn[e[u][i]] == 0) {
      dfs_cl(e[u][i]);
      low[u] = min(low[e[u][i]], low[u]);
    } else if (inst[e[u][i]]) {
      low[u] = min(dfn[e[u][i]], low[u]);
    }
  }
  if (low[u] == dfn[u]) {
    while (nTop > 0) {
      link[u].push_back(sta[nTop - 1]);
      link_head[sta[nTop - 1]] = u;
      inst[sta[nTop - 1]] = false;
      nTop--;
      if (sta[nTop] == u) break;
    }
  }
}
int dfs_ol(int u, int k) {
  if (dp[u][k] != -1) return dp[u][k];
  int i, j;
  int qe = 0;
  int qs = 0;
  int uu = link_head[u];
  for (i = 0; i < link[uu].size(); i++) {
    for (j = 0; j < d; j++) {
      ok[link[uu][i]][j] = false;
    }
  }
  ok[u][k] = true;
  q[qe++] = u * 55 + k;
  while (qs < qe) {
    int cu = q[qs] / 55;
    int ck = q[qs] % 55;
    qs++;
    for (i = 0; i < e[cu].size(); i++) {
      if (link_head[e[cu][i]] == link_head[u]) {
        int nk = (ck + 1) % d;
        if (ok[e[cu][i]][nk] == false) {
          ok[e[cu][i]][nk] = true;
          q[qe++] = e[cu][i] * 55 + nk;
        }
      }
    }
  }
  int tmp = 0;
  for (i = 0; i < link[uu].size(); i++) {
    bool flag = false;
    for (j = 0; j < d; j++) {
      if (mo[link[uu][i]][j] && ok[link[uu][i]][j]) {
        flag = true;
        break;
      }
    }
    if (flag) tmp++;
  }
  int tmp2 = 0;
  int l;
  for (l = 0; l < link[uu].size(); l++) {
    int c = link[uu][l];
    for (i = 0; i < e[c].size(); i++) {
      if (link_head[e[c][i]] != uu) {
        for (j = 0; j < d; j++) {
          if (ok[c][j]) {
            tmp2 = max(tmp2, dfs_ol(e[c][i], (j + 1) % d));
          }
        }
      }
    }
  }
  dp[u][k] = tmp + tmp2;
  return dp[u][k];
}
int main() {
  ios::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m >> d;
  int a, b;
  int i, j;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    e[a].push_back(b);
  }
  char ch[55];
  for (i = 0; i < n; i++) {
    cin >> ch;
    for (j = 0; j < d; j++) {
      if (ch[j] == '1') mo[i + 1][j] = 1;
    }
  }
  dfs_cl(1);
  int ans = dfs_ol(1, 0);
  cout << ans << endl;
}
