#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
struct SCC {
 public:
  int V, cnt = 0;
  vector<vector<int>> G, rG, edge;
  vector<int> vs, cmp, used;
  SCC(int node_size) : V(node_size), G(V), rG(V), cmp(V), used(V, 0) {}
  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }
  void dfs(int u) {
    used[u]++;
    for (int v : G[u])
      if (!used[v]) dfs(v);
    vs.push_back(u);
  }
  void dfs(int u, int k) {
    used[u]++;
    cmp[u] = k;
    for (int v : rG[u])
      if (!used[v]) dfs(v, k);
  }
  int solve() {
    for (int i = (0); i < (V); i++)
      if (!used[i]) dfs(i);
    for (int i = (0); i < (V); i++) used[i] = 0;
    for (int i = (vs.size() - 1); i >= 0; i--)
      if (!used[vs[i]]) dfs(vs[i], cnt++);
    return cnt;
  }
  void make_graph() {
    edge.resize(cnt);
    for (int i = (0); i < (V); i++) {
      for (int v : G[i]) {
        if (cmp[i] < cmp[v]) edge[cmp[i]].push_back(cmp[v]);
      }
    }
  }
  void clear() {
    vector<int>().swap(vs);
    vector<int>().swap(used);
    vector<vector<int>>().swap(G);
    vector<vector<int>>().swap(rG);
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, d;
  cin >> n >> m >> d;
  SCC scc(n * d);
  for (int _ = (0); _ < (m); _++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    for (int j = (0); j < (d); j++) {
      if (j != d - 1)
        scc.add_edge(x * d + j, y * d + j + 1);
      else
        scc.add_edge(x * d + j, y * d);
    }
  }
  vector<string> s(n);
  for (int i = (0); i < (n); i++) cin >> s[i];
  int k = scc.solve();
  scc.make_graph();
  scc.clear();
  vector<int> sum(k, 0), flag(k, -1);
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (d); j++) {
      if (s[i][j] == '0') continue;
      int id = i * d + j;
      if (flag[scc.cmp[id]] == i) continue;
      flag[scc.cmp[id]] = i;
      sum[scc.cmp[id]]++;
    }
  }
  int st = scc.cmp[0];
  vector<int> dp(k, -1e9);
  dp[st] = sum[st];
  for (int i = (st); i < (k); i++) {
    if (dp[i] < 0) continue;
    for (int to : scc.edge[i]) dp[to] = max(dp[to], dp[i] + sum[to]);
  }
  int ans = 0;
  for (int i = (0); i < (k); i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
