#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<math.h>
string str = "";
string str_min = "";
string str_max = "";
long int liuliang[10000];
void  chuli(string str1,string str5)
{
    int j;
    for(j = 6; j <=9;j++)
        str +=str1[j];
    for(j = 0; j <= 1;j++)
        str += str1[j];
    for(j = 3 ; j <= 4; j++)
        str += str1[j];
    for(j = 0; j <= 1; j++)
        str += str5[j];
    for(j = 3; j <= 4;j++)
        str += str5[j];
    for(j = 6; j <= 7; j++)
        str += str5[j];
}
void chuli1(string str3,string str6,string str7,string str8)
{
    int j;
    for(j = 6; j <=9; j ++)
        str_min +=str3[j];
    for(j = 0; j  <=1 ; j++)
        str_min += str3[j];
    for(j = 3 ; j <= 4; j ++)
        str_min += str3[j];
    for( j = 0; j <= 1 ; j++)
        str_min += str6[j];
    for(j = 3; j <= 4; j ++)
        str_min += str6[j];
    for(j = 6; j <= 7; j ++)
        str_min += str6[j];
    for(j = 6; j <= 9; j ++)
        str_max += str7[j];
    for(j = 0; j <= 1; j ++)
        str_max += str7[j];
    for(j = 3;j <= 4; j ++)
        str_max += str7[j];
    for(j = 0; j <= 1;j++)
        str_max += str8[j];
    for(j = 3; j <= 4; j++)
        str_max += str8[j];
    for(j = 6; j <= 7;j++)
        str_max += str8[j];
    
}
    
    
int main()
{
    long int n;
    cin >> n;
    long int i ;
    long int num = 0;
    string str2;
    string str_10,str_20,str_30,str_40;
    vector<string> v;
    int result = 0;
    for(i = 0 ; i < n ; i ++)
    {
        cin >> str2;
        cin >> str_10;
        cin >> num;
        chuli(str2,str_10);
        v.push_back(str);
    //    cout << str;
        liuliang[i] = num;
        str = "";
        num = 0;
    }
    int m;
    cin >> m;
    int j;
    for(i = 0 ; i < m ; i ++)
    {
        cin >> str_10;
        cin >> str_20;
        cin >> str_30;
        cin >> str_40;
        chuli1(str_10,str_20,str_30,str_40);
    //    cout << str_max << endl;
//        cout << endl;
//        cout << str_min << endl;
//        cout << str_max;
        for(j = 0 ; j < n;j++)
        {
            if((str_min <= v[j])&&(str_max >= v[j]))
            {
                result += liuliang[j];
            //    cout << 444444 << endl;
            }
        }
        cout << result << endl;
        result = 0;
        str_min = "";
        str_max = "";
        
    }
    return 0;
    
    
}


刚刚笔试的时候把月/日/年写成了日/月/年。。。好心塞,难怪一直是0%了,现在把日月年改过来了,运行例子是正确的。