#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#include <iomanip>
#define FRER() freopen("in.txt","r",stdin);
#define FREW() freopen("out.txt","w",stdout);
#define clr(str,x) memset(str,x,sizeof(str))
#define INF 0x3f3f3f3f
#define maxn 10010
typedef long long int ll;
using namespace std;
struct node
{
string name;
int st,len,et;
}man[maxn];
map<string,int> mp;
bool vis[maxn];
int main()
{
// FRER()
//FREW()
int n,m,nn;
string s;
clr(vis,false);
mp.clear();
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&nn);
for(int j=0;j<nn;j++)
{
cin>>s;
mp[s]=i;
}
}
int num=m;
for(int i=0;i<n;i++)
{
cin>>man[i].name>>man[i].st>>man[i].len;
if(!mp.count(man[i].name))
mp[man[i].name]=++num;
if(man[i].len>60)
man[i].len=60;
man[i].et=man[i].st+man[i].len;
}
vector<string> v;
int wait=0;
int Time=man[0].st;
for(int i=0;i<n;i++)
{
if(vis[i]==false)
{
int pos=mp[man[i].name];
v.push_back(man[i].name);
vis[i]=true;
if(Time>=man[i].st)
{
wait+=Time-man[i].st;
Time+=man[i].len;
}
else
{
Time=man[i].len+man[i].st;
}
for(int j=i+1;j<n;j++)
{
if(mp[man[j].name]==pos&&vis[j]==false)
{
if(man[j].st<=Time)
{
v.push_back(man[j].name);
vis[j]=true;
wait+=Time-man[j].st;
Time+=man[j].len;
}
else break;
}
}
}
}
for(int i=0;i<v.size();i++)
cout<<v[i]<<endl;
cout<<setprecision(1)<<fixed<<wait*1.0/n<<endl;
return 0;
}