#include <bits/stdc++.h>
using namespace std;
const int N = 100001, D = 51;
int n, m, d, cnt, num_SCC, s, scc[N][D], w[N * D], dp[N * D], dfs_low[N][D],
    dfs_num[N][D], vis[N][D];
vector<int> adj1[N], adj2[N * D];
vector<pair<int, int> > S;
int marked[N];
bool I[N][D];
void SCC(int u, int i) {
  dfs_low[u][i] = dfs_num[u][i] = cnt++;
  S.push_back({u, i});
  vis[u][i] = 1;
  int cont = (i + 1) % d;
  for (int v : adj1[u]) {
    if (dfs_num[v][cont] == -1) SCC(v, cont);
    if (vis[v][cont]) dfs_low[u][i] = min(dfs_low[v][cont], dfs_low[u][i]);
  }
  if (dfs_low[u][i] == dfs_num[u][i]) {
    ++num_SCC;
    while (1) {
      pair<int, int> p = S.back();
      S.pop_back();
      int v = p.first, k = p.second;
      if (marked[v] != num_SCC && I[v][k]) {
        marked[v] = num_SCC;
        w[num_SCC]++;
      }
      vis[v][k] = 0;
      scc[v][k] = num_SCC;
      if (u == v && i == k) break;
    }
  }
}
int magic(int c) {
  if (dp[c] != -1) return dp[c];
  int res = 0;
  for (int i = 0; i < adj2[c].size(); i++) {
    int w = adj2[c][i];
    int tmp = magic(w);
    res = max(res, tmp);
  }
  return dp[c] = res + w[c];
}
void build() {
  for (int v = 1; v <= n; v++)
    for (int i = 0; i < d; i++)
      for (int w : adj1[v]) {
        int c1 = scc[v][i], c2 = scc[w][(i + 1) % d];
        if (c1 == c2) continue;
        adj2[c1].push_back(c2);
      }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj1[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < d; j++) {
      char l;
      cin >> l;
      if (l == '1') {
        I[i][j] = 1;
      }
    }
  }
  memset(dfs_num, -1, sizeof(dfs_num));
  for (int v = 1; v <= n; v++) {
    for (int i = 0; i < d; i++) {
      if (dfs_num[v][i] == -1) SCC(v, i);
    }
  }
  build();
  memset(dp, -1, sizeof(dp));
  cout << magic(scc[1][0]);
  return 0;
}
