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;
const int maxtime = 50000;
map<string, int> sub;
int rest[4][2];
int tme[maxtime];
int val[100 + 10][maxtime];
int lastk[100 + 10][maxtime];
int last[100 + 10][maxtime];
int tot;
int fromTime(int d, int hh, int mm) { return (d - 1) * 24 * 60 + hh * 60 + mm; }
void toTime(int v, int& d, int& hh, int& mm) {
  mm = v % 60;
  v /= 60;
  hh = v % 24;
  v /= 24;
  d = v + 1;
}
bool isRest(int hh, int mm) {
  int it = fromTime(1, hh, mm);
  for (int i = 0; i < 4; i++) {
    if (it >= rest[i][0] && it <= rest[i][1]) return true;
  }
  return false;
}
struct employ {
  int dl;
  int idx;
  int len, pay;
  bool friend operator<(const employ& p1, const employ& p2) {
    return p1.dl < p2.dl;
  }
};
int n, m, nk;
string names[100 + 10];
char line[100 + 10];
employ es[100 + 10];
void pass(int idx) {
  copy(val[idx - 1], val[idx - 1] + tot, val[idx]);
  copy(last[idx - 1], last[idx - 1] + tot, last[idx]);
  copy(lastk[idx - 1], lastk[idx - 1] + tot, lastk[idx]);
  int cost = es[idx].len;
  int i;
  for (i = tot - 1; i >= 0 && tme[i] >= es[idx].dl; i--)
    ;
  if (i < cost) return;
  for (; i >= cost; i--) {
    if (val[idx][i - cost] + es[idx].pay > val[idx][i]) {
      val[idx][i] = val[idx][i - cost] + es[idx].pay;
      last[idx][i] = idx;
      lastk[idx][i] = idx - 1;
    }
  }
}
void output(int x, int k) {
  if (last[k][x] <= 0) return;
  output(x - es[last[k][x]].len, lastk[k][x]);
  int dd, h1, m1, dl, h2, m2;
  toTime(tme[x], dd, h1, m1);
  toTime(tme[x - es[last[k][x]].len + 1], dl, h2, m2);
  printf("%d %d %02d:%02d %d %02d:%02d\n", es[last[k][x]].idx, dl, h2, m2, dd,
         h1, m1);
}
int main() {
  cin >> m >> n >> nk;
  int cost, dd, h1, m1, h2, dl, m2;
  for (int i = 0; i < m; i++) {
    cin >> names[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> cost;
    sub.insert(make_pair(names[i], cost));
  }
  for (int i = 0; i < 4; i++) {
    cin >> line;
    sscanf(line, "%d:%d-%d:%d", &h1, &m1, &h2, &m2);
    rest[i][0] = fromTime(1, h1, m1);
    rest[i][1] = fromTime(1, h2, m2);
  }
  tot = 1;
  tme[0] = -1;
  for (int i = 1; i <= nk; i++)
    for (int j = 0; j <= 23; j++)
      for (int k = 0; k <= 59; k++) {
        if (!isRest(j, k)) tme[tot++] = fromTime(i, j, k);
      }
  fill(last[0], last[0] + tot, -1);
  fill(lastk[0], lastk[0] + tot, -1);
  fill(val[0], val[0] + tot, 0);
  string csub;
  int pay;
  int k = 1;
  for (int i = 1; i <= n; i++) {
    cin >> csub >> dd >> line >> pay;
    sscanf(line, "%d:%d", &h1, &m1);
    if (sub.find(csub) != sub.end()) {
      es[k].len = sub[csub];
      es[k].dl = fromTime(dd, h1, m1);
      es[k].pay = pay;
      es[k].idx = i;
      k++;
    }
  }
  n = k - 1;
  sort(es + 1, es + 1 + n);
  int besti = -1, best = 0;
  for (int i = 1; i <= n; i++) {
    pass(i);
  }
  for (int i = 1; i < tot; i++) {
    if (last[n][i] > 0 && val[n][i] > best) {
      best = val[n][i];
      besti = i;
    }
  }
  if (besti < 0)
    printf("0\n0\n");
  else {
    printf("%d\n", best);
    int j = besti, k = n, tj;
    int cnt = 0;
    while (last[k][j] > 0) {
      cnt++;
      tj = j - es[last[k][j]].len;
      k = lastk[k][j];
      j = tj;
    }
    printf("%d\n", cnt);
    j = besti;
    output(j, n);
  }
  return 0;
}