#include <bits/stdc++.h>
using namespace std;
const int mxn = 100000, mxk = 50, mxw = mxn * mxk;
int n, m, k, second;
int first[mxw], dp[mxw];
bitset<mxw> a, vis;
vector<int> v[mxw];
vector<int> g[2][mxn];
stack<int> stk;
inline int ff(int x, int y, int z) {
  return k * y + (k + x % k + 1 - 2 * z) % k;
}
void dfs(int c, int t) {
  vis[c] = !t;
  for (int i : g[t][c / k])
    if (vis[ff(c, i, t)] == t) dfs(ff(c, i, t), t);
  if (t)
    v[first[c] = second].push_back(c);
  else
    stk.push(c);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[0][x].push_back(y);
    g[1][y].push_back(x);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < k; j++) {
      char c;
      cin >> c;
      a[k * i + j] = c & 1;
    }
  for (int i = 0; i < n * k; i++) {
    if (!vis[i]) dfs(i, 0);
  }
  while (!stk.empty()) {
    int c = stk.top();
    stk.pop();
    if (vis[c]) dfs(c, 1), second++;
  }
  int ret = 0;
  for (int i = 0; i < second; i++) {
    int x = 0;
    dp[i] = 0xcfcfcfcf * (first[0] != i);
    for (int j : v[i]) {
      if (!vis[j / k] && a[j]) x++, vis[j / k] = 1;
      for (int l : g[1][j / k]) dp[i] = max(dp[i], dp[first[ff(j, l, 1)]]);
    }
    for (int j : v[i]) vis[j / k] = 0;
    ret = max(ret, dp[i] += x);
  }
  cout << ret << '\n';
  return 0;
}
