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 Maxn = 105;
const int Maxd = 24 * 60;
const int Maxm = Maxd * 32;
const int Inf = 1000000000;
int m, n, k;
map<string, int> M;
int T[Maxn];
vector<pair<int, int> > seq;
int ex[Maxn], tim[Maxn], mon[Maxn];
vector<pair<int, int> > st;
int dp[Maxn][Maxm];
pair<int, int> from[Maxn][Maxm];
int sinc[Maxn][Maxm];
int getLst(int tim, int nd) {
  if (seq.size() == 1 && seq[0].second - seq[0].first + 1 >= Maxd) return Maxm;
  int pnt = 0;
  for (int i = 0; i < seq.size(); i++)
    if (seq[i].first <= tim % Maxd && tim % Maxd <= seq[i].second) {
      tim = tim - tim % Maxd + seq[i].second + 1;
      pnt = (i + 1) % int(seq.size());
      break;
    } else if (tim % Maxd < seq[i].first) {
      pnt = i;
      break;
    }
  if (seq[pnt].first <= tim % Maxd && tim % Maxd <= seq[pnt].second) {
    tim = tim - tim % Maxd + seq[pnt].second + 1;
    pnt = (pnt + 1) % int(seq.size());
  }
  while (nd && tim < Maxm) {
    if (tim % Maxd <= seq[pnt].first) {
      int col = seq[pnt].first - tim % Maxd;
      if (col >= nd) return tim + nd - 1;
      nd -= col;
      tim = tim - tim % Maxd + seq[pnt].second + 1;
    } else {
      int col = seq[pnt].first + Maxd - tim % Maxd;
      if (col >= nd) return tim + nd - 1;
      nd -= col;
      tim = tim - tim % Maxd + seq[pnt].second + 1 + Maxd;
    }
    pnt = (pnt + 1) % int(seq.size());
  }
  return tim;
}
int Count(int i, int j) {
  if (sinc[i][j] == -1) return 0;
  return 1 + Count(from[i][j].first, from[i][j].second);
}
void printTime(int tim) {
  printf("%d ", tim / Maxd + 1);
  tim %= Maxd;
  printf("%d%d:", tim / 60 / 10, tim / 60 % 10);
  tim %= 60;
  printf("%d%d", tim / 10, tim % 10);
}
void Print(int i, int j) {
  if (sinc[i][j] == -1) return;
  Print(from[i][j].first, from[i][j].second);
  printf("%d ", st[from[i][j].first].second + 1);
  printTime(sinc[i][j]);
  printf(" ");
  printTime(j);
  printf("\n");
}
int main() {
  scanf("%d %d %d", &m, &n, &k);
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    M[s] = i;
  }
  for (int i = 0; i < m; i++) scanf("%d", &T[i]);
  for (int i = 0; i < 4; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++)
      if (s[j] == ':' || s[j] == '-') s[j] = ' ';
    stringstream ss(s);
    int h1, m1, h2, m2;
    ss >> h1 >> m1 >> h2 >> m2;
    int val1 = h1 * 60 + m1;
    int val2 = h2 * 60 + m2;
    if (val1 > val2) {
      seq.push_back(pair<int, int>(val1, Maxd - 1));
      seq.push_back(pair<int, int>(0, val2));
    } else
      seq.push_back(pair<int, int>(val1, val2));
  }
  sort(seq.begin(), seq.end());
  vector<pair<int, int> > tmp;
  for (int i = 0; i < seq.size(); i++)
    if (!tmp.empty() && tmp.back().second + 1 == seq[i].first)
      tmp.back().second = seq[i].second;
    else
      tmp.push_back(seq[i]);
  seq = tmp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int d;
    string tmp;
    cin >> d >> tmp >> mon[i];
    map<string, int>::iterator it = M.find(s);
    if (it == M.end()) continue;
    ex[i] = it->second;
    for (int j = 0; j < tmp.size(); j++)
      if (tmp[j] == ':') tmp[j] = ' ';
    stringstream ss(tmp);
    int h, m;
    ss >> h >> m;
    tim[i] = (d - 1) * Maxd + h * 60 + m;
    st.push_back(pair<int, int>(tim[i], i));
  }
  sort(st.begin(), st.end());
  fill((int*)dp, (int*)dp + Maxn * Maxm, -Inf);
  dp[0][0] = 0;
  sinc[0][0] = -1;
  for (int i = 0; i < st.size(); i++)
    for (int j = 0; j < Maxm; j++)
      if (dp[i][j] >= 0) {
        if (dp[i][j] > dp[i + 1][j]) {
          dp[i + 1][j] = dp[i][j];
          from[i + 1][j] = from[i][j];
          sinc[i + 1][j] = sinc[i][j];
        }
        int a = i == 0 && j == 0 ? getLst(j, 1) : getLst(j + 1, 1);
        int b = i == 0 && j == 0 ? getLst(j, T[ex[st[i].second]])
                                 : getLst(j + 1, T[ex[st[i].second]]);
        if (b < tim[st[i].second] &&
            dp[i][j] + mon[st[i].second] > dp[i + 1][b]) {
          dp[i + 1][b] = dp[i][j] + mon[st[i].second];
          from[i + 1][b] = pair<int, int>(i, j);
          sinc[i + 1][b] = a;
        }
      }
  int bestj = 0;
  for (int j = 0; j < Maxm; j++)
    if (dp[st.size()][j] > dp[st.size()][bestj]) bestj = j;
  printf("%d\n", dp[st.size()][bestj]);
  printf("%d\n", Count(st.size(), bestj));
  Print(st.size(), bestj);
  return 0;
}