#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
typedef bitset<15> BIT;
typedef unsigned long UL;
//unordered_map<BIT,int> Map;
map<int,vector<int> > Map[1500];
vector<pair<int,int> > a;
int s[MAXN],k,n,m;
int tra[MAXN];
void debug()
{
	int x = 1;
}
void dfs(int index,int tmp)
{
	if (index==k)
	{
		for (int i=0;i<n;i++)
			Map[tmp][a[i].second & tmp].push_back(a[i].first);
		return;
	}
	tmp ^= 1<<index;
	dfs(index+1,tmp);
	tmp ^= 1<<index;
	dfs(index+1,tmp);
}
int main()
{	
	freopen("A.in","r",stdin);
	freopen("1.out","w",stdout);
	//int n,m;
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)
	{
		int score,y,tmp = 0;
		scanf("%d%d",&score,&y);
		for (int j=0;j<y;j++)
		{
			int x;
			scanf("%d",&x);
			tmp |=1<<(x-1);
		}
		a.push_back(make_pair(-score,tmp));
		tra[i+1] = tmp;
		s[i+1] = score;
	}
	sort(a.begin(),a.end());
	dfs(0,0);
	scanf("%d",&m);
	for (int i=0;i<m;i++)
	{
		int index,t;
		scanf("%d%d",&index,&t);
		int tmp = 0;
		for (int j=0;j<t;j++)
		{
			int x;
			scanf("%d",&x);
			tmp |=1<<(x-1);
		}
		//cout<<i<<' '<<tmp.to_ulong()<<' '<<s[index]<<endl;
		vector<int> &b = Map[tmp][tra[index] & tmp];
		printf("%d\n",lower_bound(b.begin(),b.end(),-s[index])-b.begin() + 1);
	}
}
