Problem: It's unbelievable, but an exam period has started at the OhWord University. It's even more unbelievable, that Valera got all the tests before the exam period for excellent work during the term. As now he's free, he wants to earn money by solving problems for his groupmates. He's made a list of subjects that he can help with. Having spoken with n of his groupmates, Valera found out the following information about them: what subject each of them passes, time of the exam and sum of money that each person is ready to pay for Valera's help.

Having this data, Valera's decided to draw up a timetable, according to which he will solve problems for his groupmates. For sure, Valera can't solve problems round the clock, that's why he's found for himself an optimum order of day and plans to stick to it during the whole exam period. Valera assigned time segments for sleep, breakfast, lunch and dinner. The rest of the time he can work.

Obviously, Valera can help a student with some subject, only if this subject is on the list. It happened, that all the students, to whom Valera spoke, have different, but one-type problems, that's why Valera can solve any problem of subject listi in ti minutes.

Moreover, if Valera starts working at some problem, he can break off only for sleep or meals, but he can't start a new problem, not having finished the current one. Having solved the problem, Valera can send it instantly to the corresponding student via the Internet.

If this student's exam hasn't started yet, he can make a crib, use it to pass the exam successfully, and pay Valera the promised sum. Since Valera has little time, he asks you to write a program that finds the order of solving problems, which can bring Valera maximum profit.

Input

The first line contains integers m, n, k (1 ≤ m, n ≤ 100, 1 ≤ k ≤ 30) — amount of subjects on the list, amount of Valera's potential employers and the duration of the exam period in days.

The following m lines contain the names of subjects listi (listi is a non-empty string of at most 32 characters, consisting of lower case Latin letters). It's guaranteed that no two subjects are the same.

The (m + 2)-th line contains m integers ti (1 ≤ ti ≤ 1000) — time in minutes that Valera spends to solve problems of the i-th subject. Then follow four lines, containing time segments for sleep, breakfast, lunch and dinner correspondingly.

Each line is in format H1:M1-H2:M2, where 00 ≤  H1, H2 ≤ 23, 00 ≤  M1, M2 ≤ 59. Time H1:M1 stands for the first minute of some Valera's action, and time H2:M2 stands for the last minute of this action. No two time segments cross. It's guaranteed that Valera goes to bed before midnight, gets up earlier than he has breakfast, finishes his breakfast before lunch, finishes his lunch before dinner, and finishes his dinner before midnight. All these actions last less than a day, but not less than one minute. Time of the beginning and time of the ending of each action are within one and the same day. But it's possible that Valera has no time for solving problems.

Then follow n lines, each containing the description of students. For each student the following is known: his exam subject si (si is a non-empty string of at most 32 characters, consisting of lower case Latin letters), index of the exam day di (1 ≤ di ≤ k), the exam time timei, and sum of money ci (0 ≤ ci ≤ 106, ci — integer) that he's ready to pay for Valera's help. Exam time timei is in the format HH:MM, where 00 ≤  HH ≤ 23, 00 ≤  MM ≤ 59. Valera will get money, if he finishes to solve the problem strictly before the corresponding student's exam begins.

Output

In the first line output the maximum profit that Valera can get. The second line should contain number p — amount of problems that Valera is to solve. In the following p lines output the order of solving problems in chronological order in the following format: index of a student, to whom Valera is to help; index of the time, when Valera should start the problem; time, when Valera should start the problem (the first minute of his work); index of the day, when Valera should finish the problem; time, when Valera should finish the problem (the last minute of his work). To understand the output format better, study the sample tests.

Examples

Input

3 3 4
calculus
algebra
history
58 23 15
00:00-08:15
08:20-08:35
09:30-10:25
19:00-19:45
calculus 1 09:36 100
english 4 21:15 5000
history 1 19:50 50


Output

150
2
1 1 08:16 1 09:29
3 1 10:26 1 10:40


Input

2 2 1
matan
codeforces
1 2
00:00-08:00
09:00-09:00
12:00-12:00
18:00-18:00
codeforces 1 08:04 2
matan 1 08:02 1


Output

3
2
2 1 08:01 1 08:01
1 1 08:02 1 08:03


Input

2 2 1
matan
codeforces
2 2
00:00-08:00
09:00-09:00
12:00-12:00
18:00-18:00
codeforces 1 08:04 2
matan 1 08:03 1


Output

2
1
1 1 08:01 1 08:02

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(T a, int n) {
  for (int i = 0; i < n; ++i) cout << a[i] << ' ';
  cout << endl;
}
template <class T>
void show(T a, int r, int l) {
  for (int i = 0; i < r; ++i) show(a[i], l);
  cout << endl;
}
const int N = 128;
const int M = 1440;
const int oo = 10000 * 10000 * 10;
int m, n, dn;
map<string, int> lis;
bool use[M] = {0};
int unext[M + 10][M + 10];
int lef;
int dp[N][M * 32];
bool take[N][M * 32];
string h_s[N];
int h_t[N];
int h_c[N];
int st[N];
bool cmp(int i, int j) { return h_t[i] < h_t[j]; }
int go(int i, int ti) {
  i = st[i];
  int need = lis[h_s[i]];
  int di = ti + (need - 1) / lef * M;
  need -= (need - 1) / lef * lef;
  di += unext[di % M][need];
  return di;
}
int cal(int dex, int t) {
  int i, j, k;
  if (t >= dn * M) return 0;
  if (dex >= n) return 0;
  int &ret = dp[dex][t];
  if (ret != -1) return ret;
  ret = 0;
  if (use[t % M]) {
    ret = cal(dex, t + 1);
    return ret;
  }
  ret = cal(dex + 1, t);
  if (lis.count(h_s[st[dex]]) == 0) return ret;
  int dt = go(dex, t);
  if (dt < h_t[st[dex]]) {
    int tv = h_c[st[dex]] + cal(dex + 1, dt + 1);
    if (tv > ret) {
      ret = tv;
      take[dex][t] = true;
    }
  }
  return ret;
}
vector<int> s_d;
vector<int> s_s;
vector<int> s_t;
void print(int dex, int t) {
  if (t >= dn * M || dex >= n) return;
  int i, j;
  if (take[dex][t]) {
    s_d.push_back(dex);
    s_s.push_back(t);
    int dt = go(dex, t);
    s_t.push_back(dt);
    print(dex + 1, dt + 1);
  } else if (use[t % M])
    print(dex, t + 1);
  else
    print(dex + 1, t);
}
void solve() {
  int i, j, k;
  memset(take, 0, sizeof(take));
  memset(dp, -1, sizeof(dp));
  int ans = cal(0, 0);
  print(0, 0);
  printf("%d\n", ans);
  printf("%d\n", s_d.size());
  for (i = 0; i < s_d.size(); ++i) {
    printf("%d ", st[s_d[i]] + 1);
    printf("%d %02d:%02d ", s_s[i] / M + 1, (s_s[i] % M) / 60, s_s[i] % 60);
    printf("%d %02d:%02d\n", s_t[i] / M + 1, (s_t[i] % M) / 60, s_t[i] % 60);
  }
}
int main() {
  int i, j, cas = 0;
  scanf("%d %d %d", &m, &n, &dn);
  vector<string> name;
  for (i = 0; i < m; ++i) {
    string s;
    cin >> s;
    name.push_back(s);
  }
  for (i = 0; i < m; ++i) {
    int v;
    scanf("%d", &v);
    lis[name[i]] = v;
  }
  lef = 1440;
  for (i = 0; i < 4; ++i) {
    int h1, m1, h2, m2;
    scanf("%d:%d-%d:%d\n", &h1, &m1, &h2, &m2);
    int s = h1 * 60 + m1;
    int t = h2 * 60 + m2;
    for (j = s; j != t; j = (j + 1) % 1440) {
      use[j] = true;
      --lef;
    }
    use[j] = true;
    --lef;
  }
  for (i = 0; i < M; ++i) {
    if (use[i]) continue;
    unext[i][1] = i;
    for (j = 2; j <= lef; ++j) {
      int k = unext[i][j - 1] + 1;
      if (k == M) k = 0;
      while (use[k]) {
        ++k;
        if (k == M) k = 0;
      }
      unext[i][j] = k;
    }
  }
  for (i = 0; i < M; ++i) {
    if (use[i]) continue;
    for (j = 1; j <= lef; ++j) {
      int k = unext[i][j];
      if (k >= i)
        unext[i][j] = k - i;
      else
        unext[i][j] = M - i + k;
    }
  }
  for (i = 0; i < n; ++i) {
    cin >> h_s[i];
    int a, b, d;
    scanf(" %d %d:%d %d\n", &d, &a, &b, &h_c[i]);
    h_t[i] = d * M - M + a * 60 + b;
    st[i] = i;
  }
  sort(st, st + n, cmp);
  solve();
  return 0;
}