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 dzien = 24 * 60;
struct stu {
  int czas, start, koszt, nr;
};
struct stan {
  int akt_kon, ost_kon, ost_prop;
};
struct Odp {
  int nr_stu, d2, d1;
  string g2, g1;
};
bool por(stu a, stu b) {
  if (a.start < b.start) return true;
  if (a.start > b.start) return false;
  if (a.nr < b.nr) return true;
  return false;
}
string NaStr(int x) {
  if (x == 0) return "";
  string wyn = "";
  while (x != 0) {
    wyn = (char)(x % 10 + '0') + wyn;
    x /= 10;
  }
  return wyn;
}
int Conv1(string s, int i) {
  int h = (s[i] - '0') * 10 + (s[i + 1] - '0');
  int m = (s[i + 3] - '0') * 10 + (s[i + 4] - '0');
  return h * 60 + m;
}
int Conv2(int x) { return x / dzien + 1; }
string Conv3(int x) {
  x -= (x / dzien) * dzien;
  int g = x / 60;
  x -= (x / 60) * 60;
  int m = x;
  string sg = NaStr(g);
  string sm = NaStr(m);
  while (sg.size() < 2) sg = "0" + sg;
  while (sm.size() < 2) sm = "0" + sm;
  return sg + ":" + sm;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, k;
  cin >> m >> n >> k;
  vector<string> przed(m);
  vector<int> czas(m);
  for (int i = 0; i < m; ++i) cin >> przed[i];
  for (int i = 0; i < m; ++i) cin >> czas[i];
  vector<bool> w(k * dzien, true);
  for (int i = 0; i < 4; ++i) {
    string t;
    cin >> t;
    int pocz = Conv1(t, 0);
    int kon = Conv1(t, 6);
    for (int j = 0; j < k; ++j)
      for (int l = j * dzien + pocz; l <= j * dzien + kon; ++l) w[l] = false;
  }
  vector<stu> prop;
  for (int i = 0; i < n; ++i) {
    string a, c;
    int b, d;
    cin >> a >> b >> c >> d;
    for (int j = 0; j < m; ++j)
      if (a == przed[j])
        prop.push_back({czas[j], (b - 1) * dzien + Conv1(c, 0), d, i});
  }
  if (prop.size() == 0) {
    cout << "0" << endl << "0";
    return 0;
  }
  sort(prop.begin(), prop.end(), por);
  vector<vector<int> > pocz(prop.size(), vector<int>(k * dzien, -1));
  for (int i = 0; i < prop.size(); ++i) {
    int L = 0;
    while (L < k * dzien && !w[L]) ++L;
    if (L == k * dzien) continue;
    int P = L + 1;
    int il = 1;
    while (P < k * dzien && il < prop[i].czas) {
      if (w[P]) ++il;
      ++P;
    }
    if (il < prop[i].czas) continue;
    --P;
    pocz[i][P] = L;
    while (true) {
      ++P;
      while (P < k * dzien && !w[P]) ++P;
      if (P == k * dzien) break;
      ++L;
      while (L < k * dzien && !w[L]) ++L;
      pocz[i][P] = L;
    }
  }
  vector<vector<int> > dp(k * dzien, vector<int>(prop.size()));
  vector<vector<stan> > pop(k * dzien, vector<stan>(prop.size()));
  for (int i = 0; i < prop.size(); ++i) {
    if (prop[i].czas == 1 && w[0] && prop[i].start > 0) {
      dp[0][i] = prop[i].koszt;
      pop[0][i] = {0, -1, -1};
    } else {
      dp[0][i] = 0;
      pop[0][i] = {-1, -1, -1};
    }
  }
  for (int i = 1; i < k * dzien; ++i) {
    for (int j = 0; j < prop.size(); ++j) {
      dp[i][j] = dp[i - 1][j];
      pop[i][j] = pop[i - 1][j];
      if (pocz[j][i] == -1 || i >= prop[j].start) continue;
      if (prop[j].koszt > dp[i][j]) {
        dp[i][j] = prop[j].koszt;
        pop[i][j] = {i, -1, -1};
      }
      if (pocz[j][i] == 0) continue;
      for (int l = 0; l < j; ++l) {
        int ost_czas = pocz[j][i] - 1;
        if (dp[ost_czas][l] == 0) continue;
        int nowy_koszt = dp[ost_czas][l] + prop[j].koszt;
        if (nowy_koszt > dp[i][j]) {
          dp[i][j] = nowy_koszt;
          pop[i][j] = {i, pop[ost_czas][l].akt_kon, l};
        }
      }
    }
  }
  int akt_i = k * dzien - 1, akt_j = 0;
  for (int i = 0; i < prop.size(); ++i)
    if (dp[k * dzien - 1][i] > dp[akt_i][akt_j]) akt_j = i;
  if (dp[akt_i][akt_j] == 0) {
    cout << "0" << endl << "0";
    return 0;
  }
  akt_i = pop[akt_i][akt_j].akt_kon;
  cout << dp[akt_i][akt_j] << endl;
  vector<Odp> odp;
  while (akt_i != -1) {
    odp.push_back({prop[akt_j].nr + 1, Conv2(akt_i), Conv2(pocz[akt_j][akt_i]),
                   Conv3(akt_i), Conv3(pocz[akt_j][akt_i])});
    int nowy_i = pop[akt_i][akt_j].ost_kon;
    int nowy_j = pop[akt_i][akt_j].ost_prop;
    akt_i = nowy_i;
    akt_j = nowy_j;
  }
  reverse(odp.begin(), odp.end());
  cout << odp.size() << endl;
  for (int i = 0; i < odp.size(); ++i)
    cout << odp[i].nr_stu << " " << odp[i].d1 << " " << odp[i].g1 << " "
         << odp[i].d2 << " " << odp[i].g2 << endl;
  return 0;
}