#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int u[100005], v[100005], D;
char s[100005][55];
vector<int> mp[5000005];
int gid(int x, int d) { return n * d + x; }
int dfn[5000005], sta[5000005], low[5000005], color, ii, cnt, belong[5000005];
bool ins[5000005], dv[5000005];
int dp[5000005];
inline void tarjan(int x) {
  dfn[x] = low[x] = ++ii;
  sta[++cnt] = x;
  ins[x] = 1;
  for (int child : mp[x]) {
    if (!dfn[child]) {
      tarjan(child);
      low[x] = min(low[x], low[child]);
    } else if (ins[child]) {
      low[x] = min(low[x], dfn[child]);
    }
  }
  if (dfn[x] == low[x]) {
    ++color;
    int t;
    vector<int> tmp;
    do {
      t = sta[cnt];
      cnt--;
      ins[t] = 0;
      belong[t] = color;
      int z = t % n;
      if (z == 0) z = n;
      if (s[z][(t + n - 1) / n] == '1') {
        if (!dv[z]) {
          dv[z] = 1;
          tmp.push_back(z);
          dp[color]++;
        }
      }
    } while (dfn[t] != low[t]);
    for (int z : tmp) dv[z] = 0;
  }
}
void fmain(int tid) {
  scanf("%d%d%d", &n, &m, &D);
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%d%d", u + i, v + i);
  }
  debug = u[1] == 52097 && v[1] == 95427;
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%s", s[i] + 1);
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    int x = u[i], y = v[i];
    for (int(j) = 0; (j) < (int)(D); (j)++) {
      mp[gid(x, j)].push_back(gid(y, (j + 1) % D));
    }
  }
  tarjan(1);
  int N = D * n;
  for (int(i) = 1; (i) <= (int)(N); (i)++) {
    mp[i].clear();
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    int x = u[i], y = v[i];
    for (int(j) = 0; (j) < (int)(D); (j)++) {
      int X = gid(x, j), Y = gid(y, (j + 1) % D);
      if (belong[X] == 0 || belong[Y] == 0 || belong[X] == belong[Y]) continue;
      mp[belong[X]].push_back(belong[Y]);
    }
  }
  for (int(i) = 1; (i) <= (int)(color); (i)++) {
    int bg = 0;
    for (int c : mp[i]) maxtt(bg, dp[c]);
    dp[i] += bg;
  }
  printf("%d\n", dp[belong[1]]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
