#include <iostream>
#include <vector>
#include <algorithm>

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])
        {
            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].d1 << " " << odp[i].g2 << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

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;
}


#include <iostream>
#include <vector>
#include <algorithm>

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});
    }
    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])
        {
            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].d1 << " " << odp[i].g2 << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

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])
        {
            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;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 110;
const int M = 43210;
const int L = 16;

struct E
{
    int w,x,p,z;
    E(){}
    E(int _w,int _x,int _p,int _z):w(_w),x(_x),p(_p),z(_z){}
};
bool operator < (E a, E b){ return a.x < b.x ; }

int n,m,p,a[N];
map<string,int> A;

int  f[N][M];
int  g[N][M];
int  w[M][L];
bool v[M];

vector<E> B;

int gg(int x,int y)
{
    int p=x;
    for(int i=0,p2=p;i<L;i++)
        if((y>>i)&1)p=w[p2][i],p2=p+1;
    return p;
}

void writeAns(int x,int y,int z)
{
    if(g[x][y]==-1)
        printf("%d\n",z);
    else
    if(g[x][y]==y)
        writeAns(x-1,y,z);
    else
    {
        writeAns(x-1,g[x][y],z+1);
        int l=w[g[x][y]][0],r=y-1;
        printf("%d %d %02d:%02d %d %02d:%02d\n",B[x-1].z+1,l/1440+1,l%1440/60,l%60,r/1440+1,r%1440/60,r%60);
    }
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d%d",&n,&m,&p);

    for(int i=0,t=0;i<n;i++)
    {
        string s;
        cin>>s;
        A[ s ] = t++;
    }

    for(int i=0;i<n;i++)
        scanf("%d",a+i);

    for(int i=0;i<4;i++)
    {
        int x0,y0,x1,y1;

        scanf("%2d:%2d-%2d:%2d",&x0,&y0,&x1,&y1);

        for(int j=0;j<p;j++)
            for(int k = x0 * 60 + y0; k <= x1 * 60 + y1; k++)
                v[ j * 1440 + k ] = 1;
    }

    int P = p * 1440;
    for(int j=0;j< L; j++)
        w[P][j]=P-1;

    for(int i=P-1;i>=0;i--)
    {
        if(v[i])
            w[i][0] = w[i+1][0];
        else
            w[i][0]=i;

        for(int j = 1;j< L; j++)
            w[i][j] = w[w[i][j-1]+1][j-1];
    }

    for(int i=0;i<m;i++)
    {
        string s;
        cin>>s;
        int z,x,y,p;
        scanf("%d%2d:%2d%d",&z,&x,&y,&p),--z;

        if (!A.count(s))continue;

        B.push_back( E( A[ s ], z * 1440 + x * 60 + y, p, i ) );
    }

    sort(B.begin(),B.end());

    m = (int)(int)(int)B.size();
    memset(g,-1,sizeof g);
    for(int i=0;i<m;i++)
        for(int j=0;j<P;j++)
        {
            if(f[i][j]>f[i+1][j])
                f[i+1][j]=f[i][j],g[i+1][j]=j;
            int z=gg(j,a[B[i].w]);
            if(z>=B[i].x)continue;
            if(f[i][j]+B[i].p>f[i+1][z+1])
                f[i+1][z+1]=f[i][j]+B[i].p,g[i+1][z+1]=j;
        }
    int S=0,T=0;
    for(int i=0;i<=P;i++)if(f[m][i]>S)S=f[m][i],T=i;

    printf("%d\n",S);
    writeAns(m,T,0);

    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<=0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(bound!=0) {
                       if(qk[bound][last-1]!=-1) {
                           if(prevFree==-1)
                                a=fit;
                           else {
                               if(prevFree<1){
                                   printf("error4 %d %d %d\n",prevFree,last,bound); break;
                               }
                               a=dp[i-1][prevFree]+fit;
                           }
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
           if(get<0>(s)>get<0>(e)) {
               printf("%d %d\n",get<1>(tu),get<2>(tu));
           } else if(get<0>(s)==get<0>(e)) {
               if(get<1>(s)>get<1>(e)) {
                   printf("%d %d\n",get<1>(tu),get<2>(tu));
               } else if(get<1>(s)==get<1>(e)&&get<2>(s)>get<2>(e))
                   printf("%d %d\n",get<1>(tu),get<2>(tu));
           }
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<=0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        if(start>end) {
            printf("%d %d %d %d %d %d\n",bound,last-1,tSlot[bound],qo[bound]
                   ,start,end);
        }
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(bound!=0) {
                       if(qk[bound][last-1]!=-1) {
                           if(prevFree==-1)
                                a=fit;
                           else {
                               if(prevFree<1){
                                   printf("error4 %d %d %d\n",prevFree,last,bound); break;
                               }
                               a=dp[i-1][prevFree]+fit;
                           }
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else {
                           if(prevFree<1){
                               printf("error4 %d %d\n",prevFree,last); break;
                           }
                           a=dp[i-1][prevFree]+fit;
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           assert(tempi>=0);
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               assert(tempi>=0);
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else a=dp[i-1][prevFree]+fit,assert(prevFree>=1);
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else {
                           if(prevFree<1){
                               printf("error4 %d\n",prevFree); break;
                           }
                           a=dp[i-1][prevFree]+fit;
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           assert(tempi>=0);
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               assert(tempi>=0);
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else a=dp[i-1][prevFree]+fit,assert(prevFree>=1);
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        scanf("%d%d%d",&m,&n,&k);
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       a=dp[i-1][prevFree]+fit;
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else {
                           if(prevFree<1){
                               printf("error4 %d %d %d\n",prevFree,last,bound); break;
                           }
                           a=dp[i-1][prevFree]+fit;
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(bound!=0) {
                       if(qk[bound][last-1]!=-1) {
                           if(prevFree==-1)
                                a=fit;
                           else {
                               if(prevFree<1){
                                   printf("error4 %d %d %d\n",prevFree,last,bound); break;
                               }
                               a=dp[i-1][prevFree]+fit;
                           }
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        scanf("%d%d%d",&m,&n,&k);
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else a=dp[i-1][prevFree]+fit,assert(prevFree>=1);
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        scanf("%d%d%d",&m,&n,&k);
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else a=dp[i-1][prevFree]+fit,assert(prevFree>=1);
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(qk[bound][last-1]!=-1) {
                       if(prevFree==-1)
                            a=fit;
                       else {
                           if(prevFree<1){
                               printf("error4\n"); break;
                           }
                           a=dp[i-1][prevFree]+fit;
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
#define rep(flag,a,b) for(int flag=(a);flag<=b;flag++)
#define Rep(flag,a,b) for(int flag=(a);flag>=b;flag--)
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
const int MAX=4e4+5e3,MAX2=1005,MAX3=105;

#define DEBUG
int dp[MAX3][MAX],s[MAX3][MAX],tSlot[MAX];
int qo[MAX],qk[MAX][MAX2];
int slot(int d,int h,int m) {
    return (d-1)*1440+h*60+m+1;
}
tuple<int,int,int> times(int n) {
    int d=int(n/1440)+1,h,m;
    int temp=n%1440;
    if(temp==0) --d,h=23,m=59;
    else {
        if(temp%60==0) {
            h=temp/60-1;
            m=59;
        } else {
            h=int(temp/60);
            m=temp%60-1;
        }
    }
    return tuple<int,int,int> {d,h,m};
}
int m,n,k;
vector<string> subj;
vector<int> endure;
unordered_map<string,int> table;
int sh,sm,eh,em,maxTime;
vector<tuple<string,int,int,int>> task;
vector<tuple<int,int,int>> ans;
void getAns(int n,int t) {
    if(n==0||t<1) return ;
    if(s[n][t]==1) {
        string &name=get<0> (task[n]); int ltime=get<1> (task[n]);
        int last=table[name];
        int bound=min(t,ltime);
        int prevFree=qk[bound][last];
        getAns(n-1,prevFree);
        if(last-1<0||bound<=0||bound>=MAX||last-1>=MAX2) {
            printf("error1\n"); return ;
        }
        int start=qk[bound][last-1],end=tSlot[bound]==0? bound:qo[bound];
        ans.push_back(make_tuple(get<3>(task[n]),start,end));
    } else getAns(n-1,t);
}
bool less2(const tuple<string,int,int,int> &a,
           const tuple<string,int,int,int> &b) {
    return get<1> (a)<get<1> (b);
}

bool less1(const tuple<int,int,int> &a,const tuple<int,int,int> &b) {
    return get<1>(a)<get<2>(b);
}

int main() {
    #ifdef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
    //hh
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    int cases=1;
    while(cases--) {
    #endif
        mem(tSlot);
        //scanf("%d%d%d",&m,&n,&k);
        cin>>m>>n>>k;
        rep(i,1,m) {
            string s;
            cin>>s;
            subj.push_back(s);
        }
        rep(i,1,m) {
            int t; cin>>t;
            endure.push_back(t);
        }
        rep(i,0,m-1) table.insert({subj[i],endure[i]});
        int timeSeg=4;
        while(timeSeg--) {
            char c;
            cin>>sh>>c>>sm>>c>>eh>>c>>em;
            //scanf("%d:%d-%d:%d",&sh,&sm,&eh,&em);
            rep(d,1,k) {
                int start=slot(d,sh,sm);
                int end=slot(d,eh,em);
               // printf("(%d,%d)\n",start,end);
                rep(slot,start,end) tSlot[slot]=1;
            }
       }
       maxTime=k*1440;
       qo[1]=-1;
       rep(i,2,maxTime) {
           if(tSlot[i-1]==1) qo[i]=qo[i-1];
           else qo[i]=i-1;
       }
       rep(i,1,maxTime) {
           int consume=0,tempi=i;
           qk[i][consume]=tSlot[i]==0? i:qo[i];
           //assert(tempi>=0);
           if(tempi<0) {
               printf("error2\n"); break;
           }
           while(tempi!=-1&&(tSlot[tempi]==0||qo[tempi]!=-1)) {
               //assert(tempi>=0);
               if(tempi<0) {
                   printf("error2\n"); break;
               }
               if(tSlot[tempi]==1) tempi=qo[qo[tempi]];
               else tempi=qo[tempi];
               consume++;
               qk[i][consume]=tempi;
               if(consume==1000) break;
           }
           if(consume<1000) {
               rep(j,consume+1,1000) qk[i][j]=-1;
           }
       }
	   task.resize(n+1);
       rep(i,1,n) {
           string s; int d,h,m,fit; char c;
           cin>>s>>d>>h>>c>>m>>fit;
           int dd=slot(d,h,m); task[i]=make_tuple(s,dd-1,fit,i);
       }
       sort(task.begin()+1,task.begin()+n+1,less2);
      /* rep(i,1,n) {
           auto &t=task[i];
           cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
       } */

	   rep(t,1,maxTime) dp[0][t]=0;
       rep(i,1,n) {
           rep(t,1,maxTime) {
               string &name=get<0>(task[i]);
               int ltime=get<1>(task[i]),fit=get<2>(task[i]);
               if(table.find(name)==table.end()) {
                   dp[i][t]=dp[i-1][t];
                   s[i][t]=0;
               } else {
                   int last=table[name];
                   int bound=min(t,ltime);
                   int a=INT_MIN,b;
                   if(bound<0||last<1
                           ||bound>=MAX||last>=MAX2) {
                       printf("error3\n"); break;
                   }
                   int prevFree=qk[bound][last];
                   if(bound!=0) {
                       if(qk[bound][last-1]!=-1) {
                           if(prevFree==-1)
                                a=fit;
                           else {
                               if(prevFree<1){
                                   printf("error4 %d %d %d\n",prevFree,last,bound); break;
                               }
                               a=dp[i-1][prevFree]+fit;
                           }
                       }
                   }
                   b=dp[i-1][t];
                   if(a>b) {
                       s[i][t]=1; dp[i][t]=a;
                   } else {
                       s[i][t]=0; dp[i][t]=b;
                   }
               }
           }
       }
	   printf("%d\n",dp[n][maxTime]);
       getAns(n,maxTime);
       printf("%d\n",ans.size());
       sort(ans.begin(),ans.end(),less1);
       rep(i,0,(int)ans.size()-1) {
           auto &tu=ans[i];
           const auto &s=times(get<1>(tu)),&e=times(get<2>(tu));
           printf("%d %d %02d:%02d %d %02d:%02d\n",get<0>(tu),get<0>(s),
                  get<1>(s),get<2>(s),get<0>(e),get<1>(e),get<2>(e));
           if(get<0>(s)>get<0>(e)) {
               printf("%d %d\n",get<1>(tu),get<2>(tu));
           } else if(get<0>(s)==get<0>(e)) {
               if(get<1>(s)>get<1>(e)) {
                   printf("%d %d\n",get<1>(tu),get<2>(tu));
               } else if(get<1>(s)==get<1>(e)&&get<2>(s)>get<2>(e))
                   printf("%d %d\n",get<1>(tu),get<2>(tu));
           }
       }

    #ifdef DEBUG
    }
    #endif
    return 0;
}