#include <iostream>
#include <vector>
using namespace std;
const int BILLION = 1000'000'000;
struct ComputeUnit
{
long long u, f, d, c, e;
};
struct QueryParams
{
int N;
double tau;
vector<long long> I;
vector<long long> O;
};
int main(int argc, char* argv[])
{
//ios::sync_with_stdio(false); cin.tie(0);
int l, h;
long long F;
cin >> l >> h >> F;
double alpha, beta, gamma;
cin >> alpha >> beta >> gamma;
int n, m;
cin >> n >> m;
vector<ComputeUnit> units(n);
for (int i = 0; i < n; i++)
{
cin >> units[i].u >> units[i].f >> units[i].d >> units[i].c >> units[i].e;
units[i].f *= BILLION;
units[i].d *= BILLION;
units[i].c *= BILLION;
units[i].e *= BILLION;
}
vector<QueryParams> queries(m);
for (int j = 0; j < m; j++)
{
cin >> queries[j].N >> queries[j].tau;
queries[j].I.resize(queries[j].N);
queries[j].O.resize(queries[j].N);
for (int r = 0; r < queries[j].N; r++)
{
cin >> queries[j].I[r];
}
for (int r = 0; r < queries[j].N; r++)
{
cin >> queries[j].O[r];
}
}
for (int i = 0; i < n; i++)
{
cout << 1 << ' ' << units[i].u << ' ' << 1 << endl;
}
int P = n;
for (int j = 0; j < m; j++)
{
vector<int> A(P);
int pipeline_index = 0;
for (int r = 0; r < queries[j].N; r++)
{
cout << pipeline_index + 1 << ' ' << A[pipeline_index] + 1 << endl;
A[pipeline_index]++;
pipeline_index = (pipeline_index + 1) % P;
}
}
return 0;
}