/*
  [BAPC'07] BUS PASS
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <queue>

const int MAX = 10000;

int main () {

  int runs;
  cin>>runs;
  while (runs--) {

    int N,R;
    cin>>N>>R;
    vector<vector<int> > c(MAX);
    
    for (int i=0; i<N; i++) {
      int n,m; cin>>n>>m;
      for (int j=0; j<m; j++) {
	int k; cin>>k;
	c[n].push_back(k);
      }	
    }

    vector<int> r;
    for (int i=0; i<R; i++) {
      int n; cin>>n;
      for (int j=0; j<n; j++) {
	int k; cin>>k;
	r.push_back(k);
      }
    }

    vector<int> maxd(MAX,0);

    for (int i=0; i<r.size(); i++) {
      vector<int> d(MAX,MAX);
      queue<int> q;
      q.push(r[i]);
      d[r[i]]=1;
      while (!q.empty()) {
	int n=q.front(); q.pop();
	for (int j=0; j<c[n].size(); j++)
	  if (d[c[n][j]]==MAX) {
	    d[c[n][j]]=d[n]+1;
	    q.push(c[n][j]);
	  }
      }
      for (int j=0; j<MAX; j++) if(d[j]>maxd[j]) maxd[j]=d[j];
    }

    int star=MAX;
    for (int i=0; i<MAX; i++) if (maxd[i]<star) star=maxd[i];

    for (int i=0; i<MAX; i++)
      if (maxd[i]==star) {
	cout<<star<<" "<<i<<endl;
	break;
      }
  }

  
  return 0;
}
