#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
int n, m, k;
char input[6][500];
char str[10000100];
set<string> opend;
string Open(int &pos) {
  string ret;
  while (input[5][pos] != '\0' && input[5][pos] != ')') {
    if (isdigit(input[5][pos])) {
      int num = 0;
      while (isdigit(input[5][pos])) {
        num *= 10;
        num += input[5][pos++] - '0';
        num = min(num, m);
      }
      assert(input[5][pos] == '(');
      pos++;
      string nret = Open(pos);
      assert(input[5][pos] == ')');
      pos++;
      num = min(num, max(2, (m + (int)nret.size() - 1) / (int)nret.size()));
      string add;
      for (int i = 0; i < (int)(num); i++) {
        add += nret;
      }
      if (add.size() >= 400) {
        if (opend.count(add)) {
          num = 1;
        }
        opend.insert(add);
      }
      ret += add;
    } else {
      ret += input[5][pos++];
    }
  }
  assert((int)ret.size() <= 10000000);
  return ret;
}
int main() {
  while (scanf("%d %d %d", &n, &m, &k) > 0) {
    opend.clear();
    scanf("%s", input[5]);
    for (int i = 0; i < (int)(k); i++) {
      scanf("%s", input[i]);
    }
    {
      int pos = 0;
      string s = Open(pos);
      sprintf(str, "%s", s.c_str());
    }
    int ans = -1;
    int maxValue = -1;
    for (int iter = 0; iter < (int)(k); iter++) {
      int lv = 0;
      for (int r = 0; r < (int)(m); r++) {
        for (int l = 0; l < (int)(r + 1); l++) {
          char c = input[iter][r + 1];
          input[iter][r + 1] = 0;
          lv += strstr(str, input[iter] + l) != NULL;
          input[iter][r + 1] = c;
        }
      }
      if (lv > maxValue) {
        ans = iter + 1;
        maxValue = lv;
      }
    }
    printf("%d %d\n", ans, maxValue);
  }
}
