#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T>>;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 10;
const int maxS = 6e6 + 10;
int n, m, d, low[maxS], num[maxS], cc[maxS], w[maxS], dp[maxS], cnt = 0;
vector<int> adj[maxS];
vector<pair<int, int>> edges;
string s[maxN];
int st[maxS], last = -1;
void dfs(int u) {
  low[u] = num[u] = ++num[0];
  st[++last] = u;
  for (auto &v : adj[u]) {
    if (num[v]) {
      uin(low[u], num[v]);
    } else {
      dfs(v);
      uin(low[u], low[v]);
    }
  }
  if (low[u] == num[u]) {
    cnt++;
    int v;
    do {
      v = st[last];
      last--;
      cc[v] = cnt;
      low[v] = num[v] = 1e9;
    } while (v != u);
  }
}
void dfs2(int u) {
  num[u] = 1;
  for (auto &v : adj[u]) {
    if (!num[v]) {
      dfs2(v);
    }
    uax(dp[u], dp[v]);
  }
  dp[u] += w[u];
}
int gt(int i, int j) { return i * d + j % d; }
void solve() {
  cin >> n >> m >> d;
  while (m--) {
    int u, v;
    cin >> u >> v;
    for (int i = 0; i < (int)(d); ++i) {
      adj[gt(u, i)].emplace_back(gt(v, i + 1));
    }
    edges.emplace_back(u, v);
  }
  for (int i = 1; i <= (int)(n); ++i) {
    cin >> s[i];
  }
  for (int i = 1; i <= (int)(n); ++i) {
    for (int j = 0; j < (int)(d); ++j) {
      if (!num[gt(i, j)]) {
        dfs(gt(i, j));
      }
    }
  }
  for (int i = 1; i <= (int)(cnt); ++i) {
    adj[i].clear();
    num[i] = 0;
  }
  for (auto &e : edges) {
    int u, v;
    tie(u, v) = e;
    for (int i = 0; i < (int)(d); ++i) {
      int x = gt(u, i), y = gt(v, i + 1);
      if (cc[x] != cc[y]) {
        adj[cc[x]].emplace_back(cc[y]);
      }
    }
  }
  for (int i = 1; i <= (int)(n); ++i) {
    vector<int> vec;
    vec.reserve(d);
    for (int j = 0; j < (int)(d); ++j) {
      if (s[i][j] == '1') {
        vec.emplace_back(cc[gt(i, j)]);
      }
    }
    sort((vec).begin(), (vec).end());
    vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
    for (auto &u : vec) {
      w[u]++;
    }
  }
  dfs2(cc[gt(1, 0)]);
  cout << dp[cc[gt(1, 0)]];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
