#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double EPS = 1e-9, INF = 1e12;
struct SAComp {
  const int h, *g;
  SAComp(int h, int *g) : h(h), g(g) {}
  bool operator()(int a, int b) {
    return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a + h] < g[b + h];
  }
};
int *buildSA(char *t, int n) {
  int g[n + 1], b[n + 1], *v = new int[n + 1];
  for (int i = 0; i < (int)n + 1; i++) v[i] = i, g[i] = t[i];
  b[0] = 0;
  b[n] = 0;
  sort(v, v + n + 1, SAComp(0, g));
  for (int h = 1; b[n] != n; h *= 2) {
    SAComp comp(h, g);
    sort(v, v + n + 1, comp);
    for (int i = 0; i < (int)n; i++) b[i + 1] = b[i] + comp(v[i], v[i + 1]);
    for (int i = 0; i < (int)n + 1; i++) g[v[i]] = b[i];
  }
  return v;
}
int find(char *t, int n, char *p, int m, int *sa) {
  int a = 0, b = n;
  while (a < b) {
    int c = (a + b) / 2;
    if (strncmp(t + sa[c], p, m) < 0)
      a = c + 1;
    else
      b = c;
  }
  return strncmp(t + sa[a], p, m) == 0 ? sa[a] : -1;
}
int *buildLCP(char *t, int n, int *a) {
  int h = 0, b[n + 1], *lcp = new int[n + 1];
  for (int i = 0; i < (int)n + 1; i++) b[a[i]] = i;
  for (int i = 0; i < (int)n + 1; i++) {
    if (b[i]) {
      for (int j = a[b[i] - 1]; j + h < n && i + h < n && t[j + h] == t[i + h];
           ++h)
        ;
      lcp[b[i]] = h;
    } else
      lcp[b[i]] = -1;
    if (h > 0) --h;
  }
  return lcp;
}
int *buildRMQ(int *a, int n) {
  int logn = 1;
  for (int k = 1; k < n; k *= 2) ++logn;
  int *r = new int[n * logn];
  int *b = r;
  copy(a, a + n, b);
  for (int k = 1; k < n; k *= 2) {
    copy(b, b + n, b + n);
    b += n;
    for (int i = 0; i < (int)n - k; i++) b[i] = min(b[i], b[i + k]);
  }
  return r;
}
int minimum(int x, int y, int *rmq, int n) {
  int z = y - x, k = 0, e = 1, s;
  s = ((z & 0xffff0000) != 0) << 4;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x0000ff00) != 0) << 3;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x000000f0) != 0) << 2;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x0000000c) != 0) << 1;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x00000002) != 0) << 0;
  z >>= s;
  e <<= s;
  k |= s;
  return min(rmq[x + n * k], rmq[y + n * k - e + 1]);
}
int computeLCP(char *t, int n, char *p, int m, int o, int k) {
  int i = o;
  for (; i < m && k + i < n && p[i] == t[k + i]; ++i)
    ;
  return i;
}
int find(char *t, int n, char *p, int m, int *sa, int *rmq) {
  int l = 0, lh = 0, r = n, rh = computeLCP(t, n + 1, p, m, 0, sa[n]);
  if (!(rh == m || (sa[r] + rh < n && p[rh] < t[sa[r] + rh]))) return -1;
  for (int k = (l + r) / 2; l + 1 < r; k = (l + r) / 2) {
    int A = minimum(l + 1, k, rmq, n + 1), B = minimum(k + 1, r, rmq, n + 1);
    if (A >= B) {
      if (lh < A)
        l = k;
      else if (lh > A)
        r = k, rh = A;
      else {
        int i = computeLCP(t, n + 1, p, m, A, sa[k]);
        if ((i == m || (sa[k] + i < n && p[i] < t[sa[k] + i])))
          r = k, rh = i;
        else
          l = k, lh = i;
      }
    } else {
      if (rh < B)
        r = k;
      else if (rh > B)
        l = k, lh = B;
      else {
        int i = computeLCP(t, n + 1, p, m, B, sa[k]);
        if ((i == m || (sa[k] + i < n && p[i] < t[sa[k] + i])))
          r = k, rh = i;
        else
          l = k, lh = i;
      }
    }
  }
  return rh == m ? sa[r] : -1;
}
int n, m, k;
string s;
char *sc, t[500];
int *sa, len;
long long ck() {
  int tl = strlen(t);
  long long res = 0;
  for (int l = 0, r = 0; l < tl; l++) {
    while (r < l) r++;
    while (r < tl) {
      char tmp = t[r + 1];
      t[r + 1] = 0;
      bool res = find(sc, len, t, r - l + 1, sa) >= 0;
      t[r + 1] = tmp;
      if (!res) break;
      r++;
    }
    res += r - l;
  }
  return res;
}
string rec(int l, int r) {
  if (l >= r) return "";
  if (isdigit(s[l])) {
    int i, x = 0, d = 0;
    for (; l < r && isdigit(s[l]); l++) {
      x *= 10;
      x += s[l] - '0';
      x = min(x, 400);
    }
    for (i = l; i < r; i++) {
      if (s[i] == '(') d++;
      if (s[i] == ')') d--;
      if (d == 0) break;
    }
    string res = "", tmp = rec(l + 1, i);
    if (x == 1) return tmp;
    for (int i = 0; i < (int)x - 1; i++) {
      res += tmp;
      if (res.size() > 400) break;
    }
    if (tmp.size() * x <= 400) return res + tmp + rec(i + 1, r);
    string head = tmp.substr(0, min(400, (int)tmp.size()));
    string tail = tmp.substr(max(0, (int)tmp.size() - 400));
    string head2 = head.substr(0, max(0, (int)tmp.size() - (int)tail.size()));
    return head + "@" + tail + res + head2 + "@" + tail + rec(i + 1, r);
  }
  return s[l] + rec(l + 1, r);
}
int main() {
  cin >> n >> m >> k;
  cin >> s;
  s = rec(0, n);
  len = s.size();
  sc = (char *)malloc(len + 1);
  sprintf(sc, "%s", s.c_str());
  sa = buildSA(sc, len);
  int ansi = 0;
  long long ans = 0;
  for (int i = 0; i < (int)k; i++) {
    cin >> t;
    long long tmp = ck();
    if (tmp > ans) ans = tmp, ansi = i;
  }
  cout << ansi + 1 << " " << ans << endl;
  return 0;
}
