#include <bits/stdc++.h>
struct time_interval {
  int b, e;
};
struct student {
  std::string subject;
  int index, time, pay;
};
struct work_unit {
  int pay;
  bool take, d;
  work_unit() : pay(0), take(false), d(false) {}
};
struct work_item {
  int index, bt, et;
};
struct plan {
  int rows, cols;
  std::vector<work_unit> w;
  plan(const int rows, const int cols)
      : rows(rows), cols(cols), w(rows * cols) {}
  work_unit &operator()(const int r, const int c) { return w[c + r * cols]; }
};
static bool operator<(const student &a, const student &b) {
  return a.time < b.time   ? true
         : a.time > b.time ? false
         : a.pay < b.pay   ? true
         : a.pay > b.pay   ? false
                           : false;
}
static std::map<std::string, int> read_subjects(const int m) {
  std::vector<std::string> subject_names;
  std::map<std::string, int> subjects;
  for (int i = 0; i < m; i++) {
    char name[101];
    if (fscanf(stdin, "%100s", name) != 1 || strlen(name) == 100) {
      fprintf(stderr, "fscanf: Subject name IO error.\n");
      exit(EXIT_FAILURE);
    }
    subject_names.push_back(name);
  }
  for (int i = 0; i < m; i++) {
    int t;
    if (fscanf(stdin, "%d", &t) != 1 || t < 1 || 1000 < t) {
      fprintf(stderr, "fscanf: Subject time IO error.\n");
      exit(EXIT_FAILURE);
    }
    subjects[subject_names[i]] = t;
  }
  return subjects;
}
static int read_time() {
  int h, m;
  if (fscanf(stdin, "%d:%d", &h, &m) != 2 || h < 0 || 23 < h || m < 0 ||
      59 < m) {
    fprintf(stderr, "fscanf: Time IO error.\n");
    exit(EXIT_FAILURE);
  }
  return 60 * h + m;
}
static time_interval read_time_interval() {
  int h0, m0, h1, m1;
  if (fscanf(stdin, "%d:%d-%d:%d", &h0, &m0, &h1, &m1) != 4 || h0 < 0 ||
      23 < h0 || m0 < 0 || 59 < m0 || h1 < 0 || 23 < h1 || m1 < 0 || 59 < m1) {
    fprintf(stderr, "fscanf: Time interval IO error.\n");
    exit(EXIT_FAILURE);
  }
  return {h0 * 60 + m0, h1 * 60 + m1};
}
static std::vector<time_interval> read_action_times() {
  std::vector<time_interval> action_times;
  for (int i = 0; i < 4; i++) action_times.push_back(read_time_interval());
  return action_times;
}
static std::vector<student> read_students(
    const int n, const int k, const std::map<std::string, int> &subjects,
    const std::vector<time_interval> &action_times) {
  std::vector<student> students;
  for (int i = 0; i < n; i++) {
    char subject[101];
    int day, h, m, pay;
    if (fscanf(stdin, "%100s %d %d:%d %d", subject, &day, &h, &m, &pay) != 5 ||
        strlen(subject) == 100 || day < 1 || k < day || h < 0 || 23 < h ||
        m < 0 || 59 < m || pay < 1) {
      fprintf(stderr, "fscanf: Student IO error.\n");
      exit(EXIT_FAILURE);
    }
    const int et = (day - 1) * 24 * 60 + 60 * h + m;
    int wm = 0;
    for (int t = 0; t < et; t++) {
      bool work_minute = true;
      for (const time_interval &at : action_times)
        if (at.b <= t % (24 * 60) && t % (24 * 60) <= at.e) work_minute = false;
      wm += (work_minute ? 1 : 0);
    }
    if (subjects.find(subject) != subjects.end()) {
      students.push_back({subject, i + 1, wm, pay});
    }
  }
  std::sort(students.begin(), students.end());
  return students;
}
static int working_minutes_per_day(
    const std::vector<time_interval> &action_times) {
  int wmpd = 0;
  for (int i = 0; i < 24 * 60; i++) {
    bool work_minute = true;
    for (const time_interval &at : action_times)
      if (at.b <= i && i <= at.e) work_minute = false;
    wmpd += (work_minute ? 1 : 0);
  }
  return wmpd;
}
static int real_time(int wm, const std::vector<time_interval> &action_times) {
  int t = -1;
  for (int s = 0; s < wm + 1; t++) {
    bool work_minute = true;
    for (const time_interval &at : action_times)
      if (at.b <= (t + 1) % (24 * 60) && (t + 1) % (24 * 60) <= at.e)
        work_minute = false;
    s += (work_minute ? 1 : 0);
  }
  return t;
}
int main(int argc, char *argv[]) {
  int m, n, k;
  if (fscanf(stdin, "%d %d %d", &m, &n, &k) != 3 || m < 1 || 100 < m || n < 1 ||
      100 < n || k < 1 || 30 < k) {
    fprintf(stderr, "fscanf: Header IO error.\n");
    exit(EXIT_FAILURE);
  }
  std::map<std::string, int> subjects = read_subjects(m);
  const std::vector<time_interval> action_times = read_action_times();
  const std::vector<student> students =
      read_students(n, k, subjects, action_times);
  const int wmpd = working_minutes_per_day(action_times);
  plan p(students.size() + 1, k * wmpd);
  for (int r = 1; r < p.rows; r++)
    for (int c = 0; c < p.cols; c++) {
      const int st = subjects[students[r - 1].subject];
      if (c < students[r - 1].time && st <= c + 1) {
        const int pay =
            (st <= c ? p(r - 1, c - st).pay : 0) + students[r - 1].pay;
        p(r, c).take = (p(r - 1, c).pay < pay);
        p(r, c).pay = (p(r, c).take ? pay : p(r - 1, c).pay);
      } else {
        const int pay = (c > 0 ? p(r, c - 1).pay : 0);
        p(r, c).d = (p(r - 1, c).pay < pay);
        p(r, c).pay = (p(r, c).d ? pay : p(r - 1, c).pay);
      }
    }
  printf("%d\n", (p.cols > 0 ? p(p.rows - 1, p.cols - 1).pay : 0));
  std::vector<work_item> time_table;
  for (int r = p.rows - 1, c = p.cols - 1, d = 0; r > 0 && c >= 0;
       d = p(r, c).d, c -= p(r, c).take ? subjects[students[r - 1].subject] : d,
           r -= !d)
    if (p(r, c).take) {
      const int bt =
          real_time(c + 1 - subjects[students[r - 1].subject], action_times);
      const int et = real_time(c, action_times);
      time_table.push_back({students[r - 1].index, bt, et});
    }
  std::reverse(time_table.begin(), time_table.end());
  printf("%d\n", static_cast<int>(time_table.size()));
  for (const work_item &wi : time_table)
    printf("%d %d %02d:%02d %d %02d:%02d\n", wi.index, wi.bt / 24 / 60 + 1,
           (wi.bt / 60) % 24, wi.bt % 60, wi.et / 24 / 60 + 1,
           (wi.et / 60) % 24, wi.et % 60);
  return EXIT_SUCCESS;
}
