#include <bits/stdc++.h>
using namespace std;
int n, m, d, sz;
int A[5000003];
int no[100003][51];
bool counted[100003];
bool visited[100003][51];
bool pet[100003][51];
vector<int> vec[5000003];
vector<int> nxt[100003], bck[100003];
vector<pair<int, short> > scc;
vector<vector<pair<int, short> > > al_scc;
stack<pair<int, short> > stk;
void kosa(pair<int, short> u) {
  if (n == 99998 && m == 99999 && d == 50) {
    if (u.first > 100000 || u.second > 50) {
      cout << "KOSA : " << u.first << " " << u.second << "\n";
      fflush(stdout);
    }
  }
  visited[u.first][u.second] = 1;
  for (int v : nxt[u.first])
    if (!visited[v][(u.second + 1) % d]) kosa({v, (u.second + 1) % d});
  stk.push(u);
}
void raju(pair<int, short> u) {
  visited[u.first][u.second] = 1;
  for (int v : bck[u.first])
    if (!visited[v][(u.second - 1 + d) % d]) raju({v, (u.second - 1 + d) % d});
  scc.push_back(u);
}
void kosaraju() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < d; j++) {
      if (visited[i][j]) continue;
      kosa({i, j});
    }
  }
  memset(visited, 0, sizeof visited);
  while (stk.size()) {
    pair<int, short> u = stk.top();
    stk.pop();
    if (visited[u.first][u.second]) continue;
    scc.clear();
    raju(u);
    al_scc.push_back(scc);
  }
  for (auto v : al_scc) {
    ++sz;
    for (auto i : v) {
      if (!counted[i.first] && pet[i.first][i.second]) {
        A[sz]++;
        counted[i.first] = 1;
      }
      no[i.first][i.second] = sz;
    }
    for (auto i : v) counted[i.first] = 0;
  }
  for (auto V : al_scc) {
    for (auto u : V) {
      for (int v : nxt[u.first]) {
        if (no[u.first][u.second] == no[v][(u.second + 1) % d]) continue;
        vec[no[v][(u.second + 1) % d]].push_back(no[u.first][u.second]);
      }
    }
  }
}
int memo[5000003];
int f(int u) {
  if (no[1][0] == u)
    return A[u];
  else if (memo[u] != -1)
    return memo[u];
  int mx = -1e9;
  for (int v : vec[u]) mx = max(mx, A[u] + f(v));
  return memo[u] = mx;
}
void print_scc() {
  for (int i = 1; i <= sz; i++) printf("%d ", A[i]);
  printf("\n");
  for (auto v : al_scc) {
    for (auto i : v) printf("%d|%d ", i.first, i.second);
    printf("\n");
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    nxt[u].push_back(v);
    bck[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < d; j++) {
      char c;
      cin >> c;
      pet[i][j] = (c == '1');
    }
  }
  kosaraju();
  int mx = 0;
  memset(memo, -1, sizeof memo);
  for (int i = 1; i <= sz; i++) {
    mx = max(mx, f(i));
  }
  cout << mx << "\n";
}
