1185_F. Two Pizzas
A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9.

Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≤ f_i ≤ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≤ b_{it} ≤ 9).

The website of CodePizza restaurant has exactly m (m ≥ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≤ r_j ≤ 9, 1 ≤ a_{jt} ≤ 9) , which are included in it, and its price is c_j.

Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 10^5, 2 ≤ m ≤ 10^5) — the number of friends in the company and the number of pizzas, respectively.

Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≤ f_i ≤ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≤ b_{it} ≤ 9).

Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≤ c_j ≤ 10^9), the number of ingredients r_j (1 ≤ r_j ≤ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≤ a_{jt} ≤ 9).

Output

Output two integers j_1 and j_2 (1 ≤ j_1,j_2 ≤ m, j_1 ≠ j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.

Examples

Input


3 4
2 6 7
4 2 3 9 5
3 2 3 9
100 1 7
400 3 3 2 5
100 2 9 2
500 3 2 9 5


Output


2 3


Input


4 3
1 1
1 2
1 3
1 4
10 4 1 2 3 4
20 4 1 2 3 4
30 4 1 2 3 4


Output


1 2


Input


1 5
9 9 8 7 6 5 4 3 2 1
3 4 1 2 3 4
1 4 5 6 7 8
4 4 1 3 5 7
1 4 2 4 6 8
5 4 1 9 2 8


Output


2 4
```python
import  sys
import  math
input=sys.stdin.readline
#sys.setrecursionlimit(1000000)
I=lambda : list(map(int,input().split()))
ma =int(10000000000000000)
n,m=map(int,input().split())
a=[ma]*(515);a1=[ma]*(515);fr=[0]*(515);pos=[0]*(515)
for i in range(n):
    b=I()
    x=int(0)
    for j in range(1,b[0]+1):
        b[j]-=1
        x|=(1<<b[j])
    fr[x]+=1

min1=int(ma)
max1=int(0)
ind,ind1=int(),int()
for i in range(m):
    b=I()
    x=int(0)
    for j in range(2,b[1]+2):
        b[j]-=1
        x|=(1<<b[j])
    if a[x]!=ma:
        if fr[x]>max1:
            max1=fr[x]
            min1=a[x]+b[0]
            ind=pos[x]
            ind1=i+1
        elif fr[x]==max1:
            if b[0]+a[x]<min1:
                min1=b[0]+a[x]
                ind=pos[x]
                ind1=i+1
    if a[x]>b[0]:
        a[x]=b[0]
        pos[x]=i+1


for i in range(1,512):
    for j in range(1,512):
        if i==j or  a[i]==ma or a[j]==ma:
            continue
        k=i|j
        cnt=int(0)
        while k>0:
            cnt+=fr[k]
            k=(k-1)&(i|j)
        if cnt>max1:
            ind=pos[i]
            ind1=pos[j]
            max1=cnt
            min1=a[i]+a[j]
        if cnt==max1:
            if a[i]+a[j]<min1:
                ind=pos[i]
                ind1=pos[j]
            min1=min(min1,a[i]+a[j])

print(ind,ind1,sep=" ")
```