#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<string,string> PSS;
#define X first
#define Y second
int prices[25],s[25];
unordered_map<string,vector<PSS>> Hash;
vector<string> names;
int n;
pair<int,double> cal(string l,string r)
{
int min = 0;
double cost = 0;
int day1 = stoi(l.substr(3,2)),day2 = stoi(r.substr(3,2));
min += 24*60*(day2-day1);
cost += s[23]*60*(day2-day1);
int hour1 = stoi(l.substr(6,2)),hour2 = stoi(r.substr(6,2));
if(hour2 > hour1)
{
min += 60*(hour2-hour1);
cost += (s[hour2-1]-s[hour1-1])*60;
}
else
{
min -= 60*(hour1-hour2);
cost -= (s[hour1-1]-s[hour2-1])*60;
}
int min1 = stoi(l.substr(9,2)),min2 = stoi(r.substr(9,2));
min = min + min2 - min1;
cost = cost + prices[hour2]*min2 - prices[hour1]*min1;
return {min,cost/100};
}
int main()
{
for(int i = 0;i < 24;i++) scanf("%d",&prices[i]);
s[0] = prices[0];
for(int i = 1;i < 24;i++) s[i] = s[i-1] + prices[i];
cin >> n;
for(int i = 0;i < n;i++)
{
string name,time,state;
cin >> name >> time >> state;
if(!Hash.count(name)) names.push_back(name);
Hash[name].push_back({time,state});
}
sort(names.begin(),names.end());
for(int i = 0;i < names.size();i++)
{
string t = names[i];
bool is_ok = false;
sort(Hash[t].begin(),Hash[t].end());
for(int j = 0;j < Hash[t].size() - 1;j++)
if(Hash[t][j].Y == "on-line" && Hash[t][j+1].Y == "off-line")
is_ok = true;
if(!is_ok) continue;
cout << t << " " << Hash[t][0].X.substr(0,2) << endl;
double sum = 0;
for(int j = 0;j < Hash[t].size() - 1;j++)
{
if(Hash[t][j].Y == "on-line" && Hash[t][j+1].Y == "off-line")
{
pair<int,double> c = cal(Hash[t][j].X,Hash[t][j+1].X);
sum += c.Y;
cout << Hash[t][j].X.substr(3) << " " << Hash[t][j+1].X.substr(3) << " ";
printf("%d $%.2lf\n",c.X,c.Y);
}
}
printf("Total amount: $%.2lf\n",sum);
}
}