import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class WalkingBetweenHouses {

	public static int mod = 1000000007;
	public static long INF = (1L << 60);
	static FastScanner2 in = new FastScanner2();
	static OutputWriter out = new OutputWriter(System.out);

	public static void main(String[] args) {

		long n=in.nextLong();
		long k=in.nextLong();
		long s=in.nextLong();
		int t=(int)((s-k)/(n-1));
		int rem=(int)(s-(long)t*(n-1));
		int step=(int)k-t;
		if(s<k||t>k||rem>n-1||(t==k&&rem>0))
		{
			System.out.println("NO");
			return;
		}
		ArrayList<String> list=new ArrayList<>();
		list.add("YES\n");
		long x=0;
		for(int i=0;i<t;i++)
		{
			if(i%2==0)
			{
				x+=n-1;
				list.add(n+" ");
			}
			else
			{
				list.add(1+" ");
				x+=n-1;
				//out.print(1+" ");
			}
		}
		if(t%2==0)
		{
			int last=1;
			for(int i=1;i<rem&&step>1;i++,step--)
			{
				if(i%2==1)
					{
					list.add(2+" ");
					x++;
					//out.print(2+" ");
					}
				else
					{
					list.add(1+" ");
					x++;
					//out.print(1+" ");
					}
				rem--;
				last=(i%2)+1;
			}
			list.add((last+rem)+" ");
			x+=(rem);
		}
		else
		{
			int last=(int)n;
			for(int i=1;i<rem&&step>1;i++,step--)
			{
				if(i%2==1)
					{
					list.add((n-1)+" ");
					x++;
					//out.print((n-1)+" ");
					last=(int)n-1;
					}
				else
					{
					list.add(n+" ");
					x++;
					//out.print(n+" ");
					last=(int)n;
					}
				rem--;
			}
			list.add((last-rem)+" ");
			x+=(rem);
			//out.print(last-rem);
		}
		if(x==s)
		{
			for(String ss : list)
			{
				out.print(ss);
			}
		}
		else
		{
			System.out.println("NO");
		}

		out.close();

	}

	static class FastScanner2 {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine() {
			String fullLine = null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine = reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}
	}

	private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private static void debug(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

	private static void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class WalkingBetweenHouses {

	public static int mod = 1000000007;
	public static long INF = (1L << 60);
	static FastScanner2 in = new FastScanner2();
	static OutputWriter out = new OutputWriter(System.out);

	public static long getpos(long x,long l)
	{
		if(x-l>0)
		{
			return x-l;
		}
		else
		{
			return x+l;
		}
	}

	public static void main(String[] args) {

		long n=in.nextLong();
		long k=in.nextLong();
		long s=in.nextLong();
		if(k>s || (k*(n-1))<s)
		{
			System.out.println("NO");
			return;
		}
		out.println("YES");
		long pos=1;
		while(k>0)
		{
			long sub=min(n-1, s-(k-1));
			pos=getpos(pos, sub);
			out.print(pos+" ");
			s-=sub;
			k--;
		}
		out.close();

	}

	static class FastScanner2 {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine() {
			String fullLine = null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine = reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}
	}

	private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private static void debug(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

	private static void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class WalkingBetweenHouses {

	public static int mod = 1000000007;
	public static long INF = (1L << 60);
	static FastScanner2 in = new FastScanner2();
	static OutputWriter out = new OutputWriter(System.out);

	public static void main(String[] args) {

		long n=in.nextLong();
		long k=in.nextLong();
		long s=in.nextLong();
		int t=(int)((s-k)/(n-1));
		int rem=(int)(s-(long)t*(n-1));
		int step=(int)k-t;
		if(s<k||t>k||rem>n-1||(t==k&&rem>0))
		{
			System.out.println("NO");
			return;
		}
		ArrayList<String> list=new ArrayList<>();
		list.add("YES\n");
		long x=0;
		for(int i=0;i<t;i++)
		{
			if(i%2==0)
			{
				x+=n-1;
				list.add(n+" ");
			}
			else
			{
				list.add(1+" ");
				x+=n-1;
				//out.print(1+" ");
			}
		}
		if(t%2==0)
		{
			int last=1;
			for(int i=1;step>1;i++,step--)
			{
				if(i%2==1)
					{
					list.add(2+" ");
					x++;
					//out.print(2+" ");
					}
				else
					{
					list.add(1+" ");
					x++;
					//out.print(1+" ");
					}
				rem--;
				last=(i%2)+1;
			}
			list.add((last+rem)+" ");
			x+=(rem);
		}
		else
		{
			int last=(int)n;
			for(int i=1;step>1;i++,step--)
			{
				if(i%2==1)
					{
					list.add((n-1)+" ");
					x++;
					//out.print((n-1)+" ");
					last=(int)n-1;
					}
				else
					{
					list.add(n+" ");
					x++;
					//out.print(n+" ");
					last=(int)n;
					}
				rem--;
			}
			list.add((last-rem)+" ");
			x+=(rem);
			//out.print(last-rem);
		}
		if(x==s)
		{
			for(String ss : list)
			{
				out.print(ss);
			}
		}
		else
		{
			System.out.println("NO");
		}

		out.close();

	}

	static class FastScanner2 {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine() {
			String fullLine = null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine = reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}
	}

	private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private static void debug(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

	private static void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}


#include <stdio.h>
#include <memory.h>
#include <vector>
#include <algorithm>
#define MN 100000
#define fs first
#define sc second
#define oo MN
#define ll long long
//#define DEBUG
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;
int n;
vector<int> d[MN];
int sz[MN], pr[MN], up[MN];
void dfs1(int p) {
	sz[p] = 1;
	for (auto q : d[p]) {
		if (sz[q] == 0) {
			dfs1(q);
			sz[p] += sz[q];
		}
	}
}
void dfs2(int p) {
	pr[p] = -1;
	for (auto q : d[p]) {
		if (sz[q] > sz[p]) pr[p] = q;
		else {
			if (sz[q] > sz[p]/2) {
				if (up[p] == -1) up[q] = p;
				else up[q] = up[p];
			}
			dfs2(q);
		}
	}
}
int query[MN], Q;
vector<int> m[2][MN], e[MN];
bool cmp(int a, int b)
{return sz[a] > sz[b];}
ll c[2][MN];
ll C(int tp, int p) {
	if (c[tp][p] != -1) return c[tp][p];
	ll r = oo;
	if (tp == 0) {
		if (query[p] != Q) {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			if (r > rr) r = rr;
			rr = 1;
			for (auto q : e[p])
				rr += C(1,q);
			if (r > rr) r = rr;
		}
	}
	else {
		r = C(0,p);
		if (query[p] == Q) {
			ll rr = 0;
			for (auto q : e[p])
				rr += MIN(C(0,q),C(1,q)+1);
			if (r > rr) r = rr;
		}
		else {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			for (auto q : e[p]) {
				if (r > rr-C(0,q)+C(1,q))
					r = rr-C(0,q)+C(1,q);
			}
		}
	}
	return c[tp][p] = r;
}
int S[MN];
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n-1; i++) {
		int j, k; scanf("%d%d",&j,&k); j--; k--;
		d[j].push_back(k);
		d[k].push_back(j);
	}
	dfs1(0);
	memset(up,-1,sizeof(up));
	dfs2(0);

	memset(S,-1,sizeof(S));
	memset(query,-1,sizeof(query));
	memset(c,-1,sizeof(c));
	for (scanf("%d",&Q); Q--;) {
		vector<int> qv;
		int ki; for (scanf("%d",&ki); ki--;) {
			int i; scanf("%d",&i); i--;
			query[i] = Q; qv.push_back(i);
		}
		bool f = false;
		for (int i = 0; i < n; i++) {
			for (auto j : d[i]) {
				if (query[i] == Q && query[j] == Q)
					f = true;
			}
		}
		if (f) {
			printf("-1\n");
			continue;
		}
		vector<int> sv; sv.push_back(0);
		for (auto i : qv) {
			while (i) {
				if (S[i] != Q) {
					S[i] = Q;
					sv.push_back(i);
				}
				if (up[i] != -1) {
					m[0][up[i]].push_back(i);
					i = up[i];
				}
				else {
					m[1][pr[i]].push_back(i);
					i = pr[i];
				}
			}
		}
		for (auto i : sv) {
			auto& v = m[0][i];
			sort(v.begin(),v.end(),cmp);
			int k = i;
			for (auto j : v) {
				if (j == k) continue;
				e[k].push_back(j);
				k = j;
			}
		}
		for (auto i : sv) {
			auto& v = m[1][i];
			sort(v.begin(),v.end(),cmp);
			int k = -1;
			for (auto j : v) {
				if (j == k) continue;
				e[i].push_back(j);
				k = j;
			}
		}
		printf("%I64d\n",C(1,0));
		for (auto i : sv) {
			m[0][i].clear();
			m[1][i].clear();
			e[i].clear();
			c[0][i] = c[1][i] = -1;
		}
	}
	return 0;
}


#include <stdio.h>
#include <memory.h>
#include <vector>
#include <algorithm>
#define MN 100000
#define fs first
#define sc second
#define oo MN
#define ll long long
//#define DEBUG
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;
int n;
vector<int> d[MN];
int sz[MN], pr[MN], up[MN];
void dfs1(int p) {
	sz[p] = 1;
	for (auto q : d[p]) {
		if (sz[q] == 0) {
			dfs1(q);
			sz[p] += sz[q];
		}
	}
}
void dfs2(int p) {
	pr[p] = -1;
	for (auto q : d[p]) {
		if (sz[q] > sz[p]) pr[p] = q;
		else {
			if (sz[q] > sz[p]/2) {
				if (up[p] == -1) up[q] = p;
				else up[q] = up[p];
			}
			dfs2(q);
		}
	}
}
int query[MN], Q;
vector<int> m[2][MN], e[MN];
bool cmp(int a, int b)
{return sz[a] > sz[b];}
ll c[2][MN];
ll C(int tp, int p) {
	if (c[tp][p] != -1) return c[tp][p];
	ll r = oo;
	if (tp == 0) {
		if (query[p] != Q) {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			if (r > rr) r = rr;
			rr = 1;
			for (auto q : e[p])
				rr += C(1,q);
			if (r > rr) r = rr;
		}
	}
	else {
		r = C(0,p);
		if (query[p] == Q) {
			ll rr = 0;
			for (auto q : e[p])
				rr += MIN(C(0,q),C(1,q)+1);
			if (r > rr) r = rr;
		}
		else {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			for (auto q : e[p]) {
				if (r > rr-C(0,q)+C(1,q))
					r = rr-C(0,q)+C(1,q);
			}
		}
	}
	return c[tp][p] = r;
}
int S[MN], sv[MN], svc;
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n-1; i++) {
		int j, k; scanf("%d%d",&j,&k); j--; k--;
		d[j].push_back(k);
		d[k].push_back(j);
	}
	dfs1(0);
	memset(up,-1,sizeof(up));
	dfs2(0);

	memset(S,-1,sizeof(S));
	memset(query,-1,sizeof(query));
	memset(c,-1,sizeof(c));
	for (scanf("%d",&Q); Q--;) {
		vector<int> qv;
		int ki; for (scanf("%d",&ki); ki--;) {
			int i; scanf("%d",&i); i--;
			query[i] = Q; qv.push_back(i);
		}
		bool f = false;
		for (int i = 0; i < n; i++) {
			for (auto j : d[i]) {
				if (query[i] == Q && query[j] == Q)
					f = true;
			}
		}
		if (f) {
			printf("-1\n");
			continue;
		}
		svc = 0; sv[svc++] = 0;
		for (auto i : qv) {
			while (i) {
				if (S[i] != Q) {
					S[i] = Q;
					sv[svc++] = i;
				}
				if (up[i] != -1) {
					m[0][up[i]].push_back(i);
					i = up[i];
				}
				else {
					m[1][pr[i]].push_back(i);
					i = pr[i];
				}
			}
		}
		for (int l = 0; l < svc; l++) {
			int i = sv[l];
			auto& v = m[0][i];
			sort(v.begin(),v.end(),cmp);
			int k = i;
			for (auto j : v) {
				if (j == k) continue;
				e[k].push_back(j);
				k = j;
			}
		}
		for (int l = 0; l < svc; l++) {
			int i = sv[l];
			auto& v = m[1][i];
			sort(v.begin(),v.end(),cmp);
			int k = -1;
			for (auto j : v) {
				if (j == k) continue;
				e[i].push_back(j);
				k = j;
			}
		}
		printf("%I64d\n",C(1,0));
		for (int l = 0; l < svc; l++) {
			int i = sv[l];
			m[0][i].clear();
			m[1][i].clear();
			e[i].clear();
			c[0][i] = c[1][i] = -1;
		}
	}
	return 0;
}


#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define MN 100000
#define fs first
#define sc second
#define oo MN
#define ll long long
//#define DEBUG
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;
int n;
vector<int> d[MN];
int sz[MN], pr[MN], up[MN];
void dfs1(int p) {
	sz[p] = 1;
	for (auto q : d[p]) {
		if (sz[q] == 0) {
			dfs1(q);
			sz[p] += sz[q];
		}
	}
}
void dfs2(int p) {
	pr[p] = -1;
	for (auto q : d[p]) {
		if (sz[q] > sz[p]) pr[p] = q;
		else {
			if (sz[q] > sz[p]/2) {
				if (up[p] == -1) up[q] = p;
				else up[q] = up[p];
			}
			dfs2(q);
		}
	}
}
set<int> Q, s;
vector<int> m[2][MN], e[MN];
bool cmp(int a, int b)
{return sz[a] > sz[b];}
ll c[2][MN];
ll C(int tp, int p) {
	if (c[tp][p] != -1) return c[tp][p];
	ll r = oo;
	if (tp == 0) {
		if (Q.find(p) == Q.end()) {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			if (r > rr) r = rr;
			rr = 1;
			for (auto q : e[p])
				rr += C(1,q);
			if (r > rr) r = rr;
		}
	}
	else {
		r = C(0,p);
		if (Q.find(p) != Q.end()) {
			ll rr = 0;
			for (auto q : e[p])
				rr += MIN(C(0,q),C(1,q)+1);
			if (r > rr) r = rr;
		}
		else {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			for (auto q : e[p]) {
				if (r > rr-C(0,q)+C(1,q))
					r = rr-C(0,q)+C(1,q);
			}
		}
	}
	return c[tp][p] = r;
}
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n-1; i++) {
		int j, k; scanf("%d%d",&j,&k); j--; k--;
		d[j].push_back(k);
		d[k].push_back(j);
	}
	dfs1(0);
	memset(up,-1,sizeof(up));
	dfs2(0);

	memset(c,-1,sizeof(c));
	int q; for (scanf("%d",&q); q--;) {
		Q.clear();
		int ki; for (scanf("%d",&ki); ki--;) {
			int i; scanf("%d",&i); i--;
			Q.insert(i);
		}
		bool f = false;
		for (int i = 0; i < n; i++) {
			for (auto j : d[i]) {
				if (Q.find(i) != Q.end() && Q.find(j) != Q.end())
					f = true;
			}
		}
		if (f) {
			printf("-1\n");
			continue;
		}
		s.clear(); s.insert(0);
		for (auto i : Q) {
			while (i) {
				s.insert(i);
				if (up[i] != -1) {
					m[0][up[i]].push_back(i);
					i = up[i];
				}
				else {
					m[1][pr[i]].push_back(i);
					i = pr[i];
				}
			}
		}
		for (auto i : s) {
			auto& v = m[0][i];
			sort(v.begin(),v.end(),cmp);
			int k = i;
			for (auto j : v) {
				if (j == k) continue;
				e[k].push_back(j);
				k = j;
			}
		}
		for (auto i : s) {
			auto& v = m[1][i];
			sort(v.begin(),v.end(),cmp);
			int k = -1;
			for (auto j : v) {
				if (j == k) continue;
				e[i].push_back(j);
				k = j;
			}
		}
		printf("%I64d\n",C(1,0));
		for (auto i : s) {
			m[0][i].clear();
			m[1][i].clear();
			e[i].clear();
			c[0][i] = c[1][i] = -1;
		}
	}
	return 0;
}


#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define MN 100000
#define fs first
#define sc second
#define oo MN
#define ll long long
//#define DEBUG
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;
int n;
vector<int> d[MN];
int sz[MN], pr[MN], up[MN];
void dfs1(int p) {
	sz[p] = 1;
	for (auto q : d[p]) {
		if (sz[q] == 0) {
			dfs1(q);
			sz[p] += sz[q];
		}
	}
}
void dfs2(int p) {
	pr[p] = -1;
	for (auto q : d[p]) {
		if (sz[q] > sz[p]) pr[p] = q;
		else {
			if (sz[q] > sz[p]/2) {
				if (up[p] == -1) up[q] = p;
				else up[q] = up[p];
			}
			dfs2(q);
		}
	}
}
set<int> Q;
map<int,vector<int>> m[2], e;
bool cmp(int a, int b)
{return sz[a] > sz[b];}
map<int,ll> c[2];
ll C(int tp, int p) {
	if (c[tp].find(p) != c[tp].end()) return c[tp][p];
	ll r = oo;
	if (tp == 0) {
		if (Q.find(p) == Q.end()) {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			if (r > rr) r = rr;
			rr = 1;
			for (auto q : e[p])
				rr += C(1,q);
			if (r > rr) r = rr;
		}
	}
	else {
		r = C(0,p);
		if (Q.find(p) != Q.end()) {
			ll rr = 0;
			for (auto q : e[p])
				rr += MIN(C(0,q),C(1,q)+1);
			if (r > rr) r = rr;
		}
		else {
			ll rr = 0;
			for (auto q : e[p])
				rr += C(0,q);
			for (auto q : e[p]) {
				if (r > rr-C(0,q)+C(1,q))
					r = rr-C(0,q)+C(1,q);
			}
		}
	}
	return c[tp][p] = r;
}
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n-1; i++) {
		int j, k; scanf("%d%d",&j,&k); j--; k--;
		d[j].push_back(k);
		d[k].push_back(j);
	}
	dfs1(0);
	memset(up,-1,sizeof(up));
	dfs2(0);
#ifdef DEBUG
	for (int i = 0; i < n; i++)
		printf("pr[%d] = %d\n",i,pr[i]);
	for (int i = 0; i < n; i++)
		printf("up[%d] = %d\n",i,up[i]);
#endif

	int q; for (scanf("%d",&q); q--;) {
		Q.clear();
		int ki; for (scanf("%d",&ki); ki--;) {
			int i; scanf("%d",&i); i--;
			Q.insert(i);
		}
		bool f = false;
		for (auto i : Q) {
			if (pr[i] != -1 && Q.find(pr[i]) != Q.end())
				f = true;
		}
		if (f) {
			printf("-1\n");
			continue;
		}
		m[0].clear(); m[1].clear();
		for (auto i : Q) {
			while (i) {
				if (up[i] != -1) {
					m[0][up[i]].push_back(i);
					i = up[i];
				}
				else {
					m[1][pr[i]].push_back(i);
					i = pr[i];
				}
			}
		}
		e.clear();
		for (auto& i : m[0]) {
			auto& v = i.sc;
			sort(v.begin(),v.end(),cmp);
			int k = i.fs;
			for (auto j : v) {
				if (j == k) continue;
				e[k].push_back(j);
				k = j;
			}
		}
		for (auto& i : m[1]) {
			auto& v = i.sc;
			sort(v.begin(),v.end());
			int k = -1;
			for (auto j : v) {
				if (j == k) continue;
				e[i.fs].push_back(j);
				k = j;
			}
		}
#ifdef DEBUG
		for (auto &i : m[0]) {
			printf("m[0][%d] = ",i.fs);
			for (auto &j : i.sc)
				printf("%d ",j);
			printf("\n");
		}
		for (auto &i : e) {
			printf("e[%d] = ",i.fs);
			for (auto &j : i.sc)
				printf("%d ",j);
			printf("\n");
		}
#endif
		c[0].clear(); c[1].clear();
		printf("%I64d\n",C(1,0));
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
set<int> g[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		g[j].insert(k),g[k].insert(j);
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			if(cnt==97)
				printf("%d\n",g[11].count(39));
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N],g[1000][1000];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		g[j][k]=true;
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			if(cnt==97)
				printf("%d\n",g[11][39]);
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			if(cnt==97)
				printf("%d %d\n",Adj[i*2-1],Adj[i*2]);
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
set<int> g[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		g[j].insert(k),g[k].insert(j);
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		if(cnt==97)
			memset(b,false,sizeof(b));
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
set<int> g[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		g[j].insert(k),g[k].insert(j);
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0,b[w[i]]=false;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
set<int> g[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		g[j].insert(k),g[k].insert(j);
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
		for(i=1;i<=K;++i)
			b[a[i]]=false;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
set<int> g[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		g[j].insert(k),g[k].insert(j);
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	int cnt=0;
	while(q--)
	{++cnt;
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			for(i=1;i<=K;++i)
				b[a[i]]=false;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
		for(i=1;i<=K;++i)
			b[a[i]]=false;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005,inf=1000000;
int n,q,i,j,k,K,l,head[N],adj[N*2],nxt[N*2],a[N],id[N],s[N],top,Head[N],Adj[N*2],Nxt[N*2],Len[N*2],w[N],num,f[N][2],p[N][20],dep[N];
bool b[N];
bool cmp(int a,int b)
{
	return id[a]<id[b];
}
void dfs(int x,int dad)
{
	id[x]=++i;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dep[adj[y]]=dep[x]+1;
			p[adj[y]][0]=x;
			dfs(adj[y],x);
		}
}
int lca(int a,int b)
{
	int c,d;
	if(dep[a]<dep[b])
		swap(a,b);
	for(c=dep[a]-dep[b],d=0;c;c>>=1,++d)
		if(c&1)
			a=p[a][d];
	if(a==b)
		return a;
	for(c=18;c>=0;--c)
		if(p[a][c]!=p[b][c])
			a=p[a][c],b=p[b][c];
	return p[a][0];
}
void addedge(int u,int v,int w)
{
	//printf("%d %d\n",u,v);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	Len[l]=Len[l-1]=w;
}
void work(int x,int dad)
{
	for(int y=Head[x];y;y=Nxt[y])
		if(Adj[y]!=dad)
			work(Adj[y],x);
	if(b[x])
	{
		f[x][1]=inf;
		f[x][0]=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
			{
				if(b[Adj[y]])
					f[x][0]+=1+f[Adj[y]][0];
				else
					f[x][0]+=min(f[Adj[y]][1],Len[y]>1?f[Adj[y]][0]+1:inf);
			}
	}
	else
	{
		int z;
		f[x][1]=1;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][1]+=min(f[Adj[y]][0],f[Adj[y]][1]);
		z=0;
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				z+=min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1]);
		f[x][1]=min(f[x][1],z);
		f[x][0]=f[x][1];
		for(int y=Head[x];y;y=Nxt[y])
			if(Adj[y]!=dad)
				f[x][0]=min(f[x][0],z-min(Len[y]>1?f[Adj[y]][0]+1:inf,f[Adj[y]][1])+f[Adj[y]][0]);
	}
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	adj[n*2-1]=1;
	nxt[n*2-1]=head[0];
	head[0]=n*2-1;
	adj[n*2]=0;
	nxt[n*2]=head[1];
	head[1]=n*2;
	i=0;
	dfs(0,-1);
	for(i=1;(1<<i)<n;++i)
		for(j=1;j<=n;++j)
			if(p[j][i-1])
				p[j][i]=p[p[j][i-1]][i-1];
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d",&K);
		for(i=1;i<=K;++i)
			scanf("%d",a+i);
		if(K<=1)
		{
			puts("0");
			continue;
		}
		sort(a+1,a+1+K,cmp);
		w[num=1]=s[top=1]=0;
		l=0;
		for(i=1;i<=K;++i)
		{
			if(lca(a[i],s[top])==s[top])
			{
				w[++num]=s[++top]=a[i];
				continue;
			}
			while(top>1)
			{
				j=lca(a[i],s[top]);
				if(id[s[top-1]]>id[j])
				{
					addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
					--top;
				}
				else if(id[s[top-1]]==id[j])
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					--top;
					break;
				}
				else
				{
					addedge(j,s[top],dep[s[top]]-dep[j]);
					w[++num]=s[top]=j;
					break;
				}
			}
			w[++num]=s[++top]=a[i];
		}
		while(top>1)
		{
			addedge(s[top-1],s[top],dep[s[top]]-dep[s[top-1]]);
			--top;
		}
		for(i=1;i<=num;++i)
			b[w[i]]=false;
		for(i=1;i<=K;++i)
			b[a[i]]=true;
		for(i=1;i<=l;++i)
			if(Len[i*2]==1&&b[Adj[i*2-1]]&&b[Adj[i*2]])
				break;
		if(i<=l)
		{
			puts("-1");
			for(i=1;i<=num;++i)
				Head[w[i]]=0;
			continue;
		}
		work(0,-1);
		printf("%d\n",min(f[0][0],f[0][1]));
		for(i=1;i<=num;++i)
			Head[w[i]]=0;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Nxc = 1e6;
inline char nc()
{
    static char buf[Nxc],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,Nxc,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    int w=1,d=0; char ch=nc();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=nc(); }
    while(ch>='0'&&ch<='9') d=(d<<3)+(d<<1)+(ch^48),ch=nc();
    return w*d;
}
inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void wn(int x) { write(x); putchar('\n'); }
const int N = 100010;
int head[N],ver[N<<1],Next[N<<1],tot,n;
void add(int x,int y) { ver[++tot]=y,Next[tot]=head[x],head[x]=tot; }
int dep[N],siz[N],son[N],f[N];
void dfs1(int x,int fa)
{
    siz[x]=1; dep[x]=dep[fa]+1; f[x]=fa;
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==fa) continue;
        dfs1(y,x); siz[x]+=siz[y];
        if(siz[son[x]]<siz[y]) son[x]=y;
    }
}
int Top[N],cnt,dfn[N];
void dfs2(int x,int fa)
{
    Top[x]=fa; dfn[x]=++cnt;
    if(son[x]) dfs2(son[x],fa);
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==f[x]||y==son[x]) continue;
        dfs2(y,y);
    }
}
int LCA(int x,int y)
{
    while(Top[x]!=Top[y])
    {
        if(f[Top[x]]<f[Top[y]]) swap(x,y);
        x=f[Top[x]];
    }
    return dep[x]<dep[y]?x:y;
}
int a[N],S[N],Stop;
int vis[N];
void insert(int x)
{
    if(Stop==0) { S[++Stop]=x; return ; }
    int lca = LCA(x,S[Stop]);
    while((Stop>1)&&(dep[lca]<dep[S[Stop-1]])) add(S[Stop-1],S[Stop]),Stop--;
    if(dep[S[Stop]]>dep[lca]) add(lca,S[Stop]),Stop--;
    if(Stop==0 || S[Stop]!=lca) S[++Stop]=lca;
    S[++Stop]=x;
}
int ans;
void dfs3(int x)
{
    if(vis[x])
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y);
            if(siz[y]) { siz[y]=0; ans++; }
        }
    }
    else
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y); siz[x]+=siz[y]; siz[y]=0;
        }
        if(siz[x]>1) { ans++; siz[x]=0; }
    }
}
bool cmp(int x,int y) { return dfn[x]<dfn[y]; }
int main()
{
    n=read();
    for(register int i=2;i<=n;i++)
    {
        int x=read(),y=read();
        add(x,y); add(y,x);
    }
    dfs1(1,0); dfs2(1,1);
    memset(head,0,sizeof(head));
    int T=read();
    while(T--)
    {
        int k=read(); tot=0; ans=0;
        memset(vis,0,sizeof(vis));
        for(register int i=1;i<=k;i++) a[i]=read(),vis[a[i]]=1;
        sort(a+1,a+1+k,cmp);
        bool flag=0;
        for(register int i=1;i<=k;i++) if(vis[f[a[i]]]) { flag=1; break; }
        if(flag) { wn(-1); continue; }
        if(a[1]!=1) S[Stop=1]=1;
        for(register int i=1;i<=k;i++) insert(a[i]);
        while(Stop) add(S[Stop-1],S[Stop]),Stop--;
        ans=0; dfs3(1); wn(ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Nxc = 1e6;
inline char nc()
{
    static char buf[Nxc],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,Nxc,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    int w=1,d=0; char ch=nc();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=nc(); }
    while(ch>='0'&&ch<='9') d=(d<<3)+(d<<1)+(ch^48),ch=nc();
    return w*d;
}
inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void wn(int x) { write(x); putchar('\n'); }
const int N = 100010;
int head[N],ver[N<<1],Next[N<<1],tot,n;
void add(int x,int y) { ver[++tot]=y,Next[tot]=head[x],head[x]=tot; }
int dep[N],siz[N],son[N],f[N];
void dfs1(int x,int fa)
{
    siz[x]=1; dep[x]=dep[fa]+1; f[x]=fa;
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==fa) continue;
        dfs1(y,x); siz[x]+=siz[y];
        if(siz[son[x]]<siz[y]) son[x]=y;
    }
}
int Top[N],cnt,dfn[N];
void dfs2(int x,int fa)
{
    Top[x]=fa; dfn[x]=++cnt;
    if(son[x]) dfs2(son[x],fa);
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==f[x]||y==son[x]) continue;
        dfs2(y,y);
    }
}
int LCA(int x,int y)
{
    while(Top[x]!=Top[y])
    {
        if(f[Top[x]]<f[Top[y]]) swap(x,y);
        x=f[Top[x]];
    }
    return dep[x]<dep[y]?x:y;
}
int a[N],S[N],Stop;
int vis[N];
void insert(int x)
{
    if(Stop==0) { S[++Stop]=x; return ; }
    int lca = LCA(x,S[Stop]);
    while((Stop>1)&&(dep[lca]<dep[S[Stop-1]])) add(S[Stop-1],S[Stop]),Stop--;
    if(dep[S[Stop]]>dep[lca]) add(lca,S[Stop]),Stop--;
    if(Stop==0 || S[Stop]!=lca) S[++Stop]=lca;
    S[++Stop]=x;
}
int ans;
void dfs3(int x)
{
    if(vis[x])
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y);
            if(vis[y]) { vis[y]=0; ans++; }
        }
    }
    else
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y); vis[x]+=vis[y]; vis[y]=0;
        }
        if(vis[x]>1) { ans++; vis[x]=0; }
    }
    head[x]=0;
}
bool cmp(int x,int y) { return dfn[x]<dfn[y]; }
int main()
{
    n=read();
    for(register int i=2;i<=n;i++)
    {
        int x=read(),y=read();
        add(x,y); add(y,x);
    }
    dfs1(1,0); dfs2(1,1);
    memset(head,0,sizeof(head));
    int T=read();
    while(T--)
    {
        int k=read(); tot=0; ans=0;
        memset(vis,0,sizeof(vis));
        for(register int i=1;i<=k;i++) a[i]=read(),vis[a[i]]=1;
        sort(a+1,a+1+k,cmp);
        bool flag=0;
        for(register int i=1;i<=k;i++) if(vis[f[a[i]]]) { flag=1; break; }
        if(flag) { wn(-1); continue; }
        if(a[1]!=1) S[Stop=1]=1;
        for(register int i=1;i<=k;i++) insert(a[i]);
        while(Stop) add(S[Stop-1],S[Stop]),Stop--;
        ans=0; dfs3(1); wn(ans);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=1e5+2,M=2e5+2;
int a[N],lj[M],nxt[M],fir[N],dfn[N],top[N],hc[N],siz[N],f[N],dep[N],st[N];
int n,m,q,i,x,y,c,bs,tp,ance,ans;
inline void read(int &x)
{
    c=getchar();
    while ((c<48)||(c>57)) c=getchar();
    x=c^48;c=getchar();
    while ((c>=48)&&(c<=57))
    {
        x=x*10+(c^48);
        c=getchar();
    }
}//快读
inline void add(int x,int y)
{
    lj[++bs]=y;
    nxt[bs]=fir[x];
    fir[x]=bs;
}//加单向边
void dfs1(int x)
{
    siz[x]=1;
    int i;
    for (i=fir[x];i;i=nxt[i]) if (lj[i]!=f[x])
    {
        dep[lj[i]]=dep[f[lj[i]]=x]+1;
        dfs1(lj[i]);
        siz[x]+=siz[lj[i]];
        if (siz[hc[x]]<siz[lj[i]]) hc[x]=lj[i];
    }
}//树剖预处理
void dfs2(int x)
{
    dfn[x]=++bs;
    if (hc[x])
    {
        int i;
        top[hc[x]]=top[x];
        dfs2(hc[x]);
        for (i=fir[x];i;i=nxt[i]) if ((lj[i]!=f[x])&&(lj[i]!=hc[x])) dfs2(top[lj[i]]=lj[i]);
    }
}//树剖预处理
inline int lca(int x,int y)
{
    while (top[x]!=top[y]) if (dep[top[x]]>dep[top[y]]) x=f[top[x]]; else y=f[top[y]];
    if (dep[x]<dep[y]) return x; return y;
}//求lca
void qs(int l,int r)//按照dfs序排序
{
    int i=l,j=r,m=dfn[a[l+r>>1]];
    while (i<=j)
    {
        while (dfn[a[i]]<m) ++i;
        while (dfn[a[j]]>m) --j;
        if (i<=j) swap(a[i++],a[j--]);
    }
    if (i<r) qs(i,r);
    if (l<j) qs(l,j);
}
inline void ins(int x)
{
    if (tp==0)
    {
        st[tp=1]=x;
        return;
    }
    ance=lca(st[tp],x);//相当于z
    while ((tp>1)&&(dep[ance]<dep[st[tp-1]]))
    {
        add(st[tp-1],st[tp]);
        --tp;
    }
    if (dep[ance]<dep[st[tp]]) add(ance,st[tp--]);
    if ((!tp)||(st[tp]!=ance)) st[++tp]=ance;
    st[++tp]=x;
}//增量构建
void dfs3(int x)
{
    int i;
    if (siz[x]) for (i=fir[x];i;i=nxt[i])
    {
        dfs3(lj[i]);
        if (siz[lj[i]])
        {
            siz[lj[i]]=0;
            ++ans;
        }
    }
    else
    {
        for (i=fir[x];i;i=nxt[i])
        {
            dfs3(lj[i]);
            siz[x]+=siz[lj[i]];
            siz[lj[i]]=0;
        }
        if (siz[x]>1)
        {
            ++ans;siz[x]=0;
        }
    }
    fir[x]=0;//这里清空
}//对每组询问的解决
int main()
{
    read(n);
    for (i=1;i<n;i++)
    {
        read(x);read(y);
        add(x,y);add(y,x);
    }
    bs=0;
    dfs1(dep[1]=1);
    dfs2(top[1]=1);
    memset(fir+1,0,n<<2);
    memset(siz+1,0,n<<2);
    read(q);
    bs=0;
    while (q--)
    {
        x=1;
        read(m);
        for (i=1;i<=m;i++)
        {
            read(a[i]);
            siz[a[i]]=1;
        }
        for (i=1;i<=m;i++) if (siz[f[a[i]]])
        {
            puts("-1");
            x=0;
            break;
        }//特判无解
        if (!x)
        {
            while (m) siz[a[m--]]=0;//清空打过的标记
            continue;
        }
        ans=0;
        qs(1,m);
        if (a[1]!=1) st[tp=1]=1;//先行添加根节点
        for (i=1;i<=m;i++) ins(a[i]);
        if (tp) while (--tp) add(st[tp],st[tp+1]);//回溯
        dfs3(1);
        siz[1]=bs=0;
        printf("%d\n",ans);
    }
}


#include <bits/stdc++.h>
using namespace std;
const int Nxc = 1e6;
inline char nc()
{
    static char buf[Nxc],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,Nxc,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    int w=1,d=0; char ch=nc();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=nc(); }
    while(ch>='0'&&ch<='9') d=(d<<3)+(d<<1)+(ch^48),ch=nc();
    return w*d;
}
inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void wn(int x) { write(x); putchar('\n'); }
const int N = 100010;
int head[N],ver[N<<1],Next[N<<1],tot,n;
void add(int x,int y) { ver[++tot]=y,Next[tot]=head[x],head[x]=tot; }
int dep[N],siz[N],son[N],f[N];
void dfs1(int x,int fa)
{
    siz[x]=1; dep[x]=dep[fa]+1; f[x]=fa;
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==fa) continue;
        dfs1(y,x); siz[x]+=siz[y];
        if(siz[son[x]]<siz[y]) son[x]=y;
    }
}
int Top[N],cnt,dfn[N];
void dfs2(int x,int fa)
{
    Top[x]=fa; dfn[x]=++cnt;
    if(son[x]) dfs2(son[x],fa);
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==f[x]||y==son[x]) continue;
        dfs2(y,y);
    }
}
int LCA(int x,int y)
{
    while(Top[x]!=Top[y])
    {
        if(f[Top[x]]<f[Top[y]]) swap(x,y);
        x=f[Top[x]];
    }
    return dep[x]<dep[y]?x:y;
}
int a[N],S[N],Stop;
int vis[N];
void insert(int x)
{
    if(Stop==0) { S[++Stop]=x; return ; }
    int lca = LCA(x,S[Stop]);
    while((Stop>1)&&(dep[lca]<dep[S[Stop-1]])) add(S[Stop-1],S[Stop]),Stop--;
    if(dep[S[Stop]]>dep[lca]) add(lca,S[Stop]),Stop--;
    if(Stop==0 || S[Stop]!=lca) S[++Stop]=lca;
    S[++Stop]=x;
}
int ans;
void dfs3(int x)
{
    if(vis[x])
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y);
            if(vis[y]) { vis[y]=0; ans++; }
        }
    }
    else
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y); vis[x]+=vis[y]; vis[y]=0;
        }
        if(vis[x]>1) { ans++; vis[x]=0; }
    }
}
bool cmp(int x,int y) { return dfn[x]<dfn[y]; }
int main()
{
    n=read();
    for(register int i=2;i<=n;i++)
    {
        int x=read(),y=read();
        add(x,y); add(y,x);
    }
    dfs1(1,0); dfs2(1,1);
    memset(head,0,sizeof(head));
    int T=read();
    while(T--)
    {
        int k=read(); tot=0; ans=0;
        memset(vis,0,sizeof(vis));
        for(register int i=1;i<=k;i++) a[i]=read(),vis[a[i]]=1;
        sort(a+1,a+1+k,cmp);
        bool flag=0;
        for(register int i=1;i<=k;i++) if(vis[f[a[i]]]) { flag=1; break; }
        if(flag) { wn(-1); continue; }
        if(a[1]!=1) S[Stop=1]=1;
        for(register int i=1;i<=k;i++) insert(a[i]);
        while(Stop) add(S[Stop-1],S[Stop]),Stop--;
        ans=0; dfs3(1); wn(ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Nxc = 1e6;
inline char nc()
{
    static char buf[Nxc],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,Nxc,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    int w=1,d=0; char ch=nc();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=nc(); }
    while(ch>='0'&&ch<='9') d=(d<<3)+(d<<1)+(ch^48),ch=nc();
    return w*d;
}
const int N = 200010;
int head[N],ver[N<<1],tot,Next[N<<1],n;
void add(int x,int y)
{
    ver[++tot]=y,Next[tot]=head[x],head[x]=tot;
}
int q[N],tmp[N],num[N],tmp_cnt;
int dfn[N],fa[N],son[N],siz[N],dep[N],Top[N],cnt;
void dfs1(int x,int f)
{
    siz[x]=1; fa[x]=f;
    dep[x]=dep[f]+1;
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==f) continue;
        dfs1(y,x);
        siz[x]+=siz[y];
        if(siz[son[x]]<siz[y]) son[x]=y;
    }
}
void dfs2(int x,int tp)
{
    dfn[x]=++cnt; Top[x]=tp;
    if(son[x]) dfs2(son[x],tp);
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(dfn[y]) continue;
        dfs2(y,y);
    }
}
int lca(int x,int y)
{
    while(Top[x]!=Top[y])
    {
        if(dep[Top[x]]<dep[Top[y]]) swap(x,y);
        x=fa[Top[x]];
    }
    if(dfn[x]>dfn[y]) return y;
    return x;
}
bool cmp(int x,int y) { return dfn[x]<dfn[y]; }
int st[N],top;
void insert(int x)
{
    if(x==1) return ;
    if(top==1) { st[++top]=x; return; }
    int fp = lca(x,st[top]);
    if(fp==st[top]) { st[++top]=x; return; }
    while(top>1&&dfn[fp]<=dfn[st[top-1]])
    {
        add(st[top-1],st[top]); top--;
        tmp[++tmp_cnt]=st[top];
    }
    if(fp!=st[top]) add(fp,st[top]),st[top]=fp,tmp[++tmp_cnt]=st[top];
    st[++top]=x;
}
int ans;
void dp(int x)
{
    int cnt=0,sum=0;
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        dp(y);
        if(num[x]&&num[y]) ans++;
        if(!num[x]&&num[y])
        {
            cnt++; sum+=num[y];
        }
    }
    if(!num[x])
    {
        if(cnt==1) num[x]+=sum;
        if(cnt>1) ans++;
    }
    head[x]=0;
}
int main()
{
    n=read();
    for(register int i=1;i<n;i++)
    {
        int x=read(),y=read();
        add(x,y),add(y,x);
    }
    dfs1(1,0);  dfs2(1,1);
    tot=0; memset(head,0,sizeof(head));
    int T=read();
    bool flag=0;
    while(T--)
    {
        int k=read();
        tot=tmp_cnt=flag=ans=0;
        for(register int i=1;i<=k;i++)
        {
            q[i]=read();
            num[q[i]]++;
        }
        for(register int i=1;i<=k;i++)
            if(num[fa[q[i]]])
            {
                cout<<-1<<endl;
                flag=1;
                break;
            }
        if(flag)
        {
            for(register int i=1;i<=k;i++) num[q[i]]=0;
            continue;
        }
        sort(q+1,q+1+k,cmp);
        st[top=1]=1; tmp[tmp_cnt=1]=1;
        for(register int i=1;i<=k;i++) insert(q[i]);
        while(top) add(st[top-1],st[top]),top--,tmp[++tmp_cnt]=st[top];
        dp(1); cout<<ans<<endl;
        for(register int i=1;i<=k;i++) num[q[i]]=0;
        for(register int i=1;i<=tmp_cnt;i++) num[tmp[i]]=0;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Nxc = 1e6;
inline char nc()
{
    static char buf[Nxc],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,Nxc,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    int w=1,d=0; char ch=nc();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=nc(); }
    while(ch>='0'&&ch<='9') d=(d<<3)+(d<<1)+(ch^48),ch=nc();
    return w*d;
}
inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void wn(int x) { write(x); putchar('\n'); }
const int N = 100010;
int head[N],ver[N<<1],Next[N<<1],tot,n;
void add(int x,int y) { ver[++tot]=y,Next[tot]=head[x],head[x]=tot; }
int dep[N],siz[N],son[N],f[N];
void dfs1(int x,int fa)
{
    siz[x]=1; dep[x]=dep[fa]+1; f[x]=fa;
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==fa) continue;
        dfs1(y,x); siz[x]+=siz[y];
        if(siz[son[x]]<siz[y]) son[x]=y;
    }
}
int Top[N],cnt,dfn[N];
void dfs2(int x,int fa)
{
    Top[x]=fa; dfn[x]=++cnt;
    if(son[x]) dfs2(son[x],fa);
    for(register int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(y==f[x]||y==son[x]) continue;
        dfs2(y,y);
    }
}
int LCA(int x,int y)
{
    while(Top[x]!=Top[y])
    {
        if(f[Top[x]]<f[Top[y]]) swap(x,y);
        x=f[Top[x]];
    }
    return dep[x]<dep[y]?x:y;
}
int a[N],S[N],Stop;
int vis[N];
void insert(int x)
{
    if(Stop==0) { S[++Stop]=x; return ; }
    int lca = LCA(x,S[Stop]);
    while((Stop>1)&&(dep[lca]<dep[S[Stop-1]])) add(S[Stop-1],S[Stop]),Stop--;
    if(dep[S[Stop]]>dep[lca]) add(lca,S[Stop]),Stop--;
    if(Stop==0 || S[Stop]!=lca) S[++Stop]=lca;
    S[++Stop]=x;
}
int ans;
void dfs3(int x)
{
    if(vis[x])
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y);
            if(vis[y]) { vis[y]=0; ans++; }
        }
    }
    else
    {
        for(register int i=head[x];i;i=Next[i])
        {
            int y=ver[i];
            dfs3(y); vis[x]+=vis[y]; vis[y]=0;
        }
        if(vis[x]>1) { ans++; vis[x]=0; }
    }
}
bool cmp(int x,int y) { return dfn[x]<dfn[y]; }
int main()
{
    n=read();
    for(register int i=2;i<=n;i++)
    {
        int x=read(),y=read();
        add(x,y); add(y,x);
    }
    dfs1(1,0); dfs2(1,1);
    memset(head,0,sizeof(head));
    int T=read();
    while(T--)
    {
        int k=read(); tot=0; ans=0; vis[1]=0;
        for(register int i=1;i<=k;i++) a[i]=read(),vis[a[i]]=1;
        sort(a+1,a+1+k,cmp);
        bool flag=0;
        for(register int i=1;i<=k;i++) if(vis[f[a[i]]]) { flag=1; break; }
        if(flag) { wn(-1); continue; }
        if(a[1]!=1) S[Stop=1]=1;
        for(register int i=1;i<=k;i++) insert(a[i]);
        while(Stop) add(S[Stop-1],S[Stop]),Stop--;
        ans=0; dfs3(1); wn(ans);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=18; ++i) f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=18; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=18; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[y][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i) Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		F[x]+=F[y]; G[x]+=G[y];
	}
	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
	else F[x]+=G[x], G[x]=1;
//	int t0=0,t1=0,t2=0;
//	for (int i=HEAD[x]; i; i=EDGE[i].next)
//	{
//		int y=EDGE[i].to; DP(y);
//		t2=min(t2+F[y],t0+min(F[y],G[y])), t0+=F[y], t1+=min(F[y],G[y]);
//	}
//	if (vis[x]) G[x]=t0, F[x]=t0+1;
//	else G[x]=t2, F[x]=min(t1+1,t0);
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k-1; ++j)
			if (a[j]==f[a[j+1]][0]) {flag=false; break;}
		Build();
		if (flag) DP(stack[1]), printf("%d\n",F[stack[1]]);
		else puts("-1");
		Clear(stack[1]);
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=17; ++i)
		f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=17; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=17; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[y][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
	cout<<u<<' '<<v<<endl;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		 ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i)
		Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
	F[x]=0; G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		F[x]+=F[y]; G[x]+=G[y];
	}
	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
	else F[x]+=G[x], G[x]=1;
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
//	freopen("data.in","r",stdin);
//	freopen("datam.out","w",stdout);
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k; ++j)
			if (vis[a[j]] && vis[f[a[j]][0]]) {flag=false; break;}
		Build();
		if (flag) DP(1), printf("%d\n",F[1]);
		else puts("-1");
		Clear(1);
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=17; ++i)
		f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=17; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=17; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[i][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		 ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i) Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
	F[x]=0; G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		F[x]+=F[y]; G[x]+=G[y];
	}
	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
	else F[x]+=G[x], G[x]=1;
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k-1; ++j)
			if (a[j]==f[a[j+1]][0]) {flag=false; break;}
		Build();
		if (flag) DP(1), printf("%d\n",F[1]);
		else puts("-1");
		Clear(1);
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=17; ++i)
		f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=17; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=17; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[i][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		 ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i) Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
//	for (int i=HEAD[x]; i; i=EDGE[i].next)
//	{
//		int y=EDGE[i].to; DP(y);
//		F[x]+=F[y]; G[x]+=G[y];
//	}
//	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
//	else F[x]+=G[x], G[x]=1;
	int t0=0,t1=0,t2=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		t2=min(t2+F[y],t0+min(F[y],G[y])), t0+=F[y], t1+=min(F[y],G[y]);
	}
	if (vis[x]) G[x]=t0, F[x]=t0+1;
	else G[x]=t2, F[x]=min(t1+1,t0);
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k-1; ++j)
			if (a[j]==f[a[j+1]][0]) {flag=false; break;}
		Build();
		if (flag) DP(1), printf("%d\n",min(F[1],G[1]));
		else puts("-1");
		Clear(1);
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=18; ++i) f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=18; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=18; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[y][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i) Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		F[x]+=F[y]; G[x]+=G[y];
	}
	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
	else F[x]+=G[x], G[x]=1;
//	int t0=0,t1=0,t2=0;
//	for (int i=HEAD[x]; i; i=EDGE[i].next)
//	{
//		int y=EDGE[i].to; DP(y);
//		t2=min(t2+F[y],t0+min(F[y],G[y])), t0+=F[y], t1+=min(F[y],G[y]);
//	}
//	if (vis[x]) G[x]=t0, F[x]=t0+1;
//	else G[x]=t2, F[x]=min(t1+1,t0);
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k-1; ++j)
			if (a[j]==f[a[j+1]][0]) {flag=false; break;}
		Build();
		if (flag) DP(1), printf("%d\n",F[1]);
		else puts("-1");
		Clear(1);
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=17; ++i)
		f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=17; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=17; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[y][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
//	cout<<u<<' '<<v<<endl;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		 ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i)
		Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
	F[x]=0; G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		F[x]+=F[y]; G[x]+=G[y];
	}
	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
	else F[x]+=G[x], G[x]=1;
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
//	freopen("data.in","r",stdin);
//	freopen("datam.out","w",stdout);
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k; ++j)
			if (vis[a[j]] && vis[f[a[j]][0]]) {flag=false; break;}
		Build();
		if (flag) DP(1), printf("%d\n",F[1]);
		else puts("-1");
		Clear(1);
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N (100009)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,u,v,m,k,dfs_num,flag;
int a[N],DFN[N],Depth[N],f[N][18],vis[N],F[N],G[N];
int head[N],num_edge;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void DFS(int x,int fa)
{
	f[x][0]=fa;
	for (int i=1; i<=17; ++i)
		f[x][i]=f[f[x][i-1]][i-1];
	DFN[x]=++dfs_num; Depth[x]=Depth[fa]+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa) DFS(edge[i].to,x);
}

int LCA(int x,int y)
{
	if (Depth[x]<Depth[y]) swap(x,y);
	for (int i=17; i>=0; --i)
		if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=17; i>=0; --i)
		if (f[x][i]!=f[y][i]) x=f[x][i], y=f[i][i];
	return f[x][0];
}

struct E{int to,next;}EDGE[N<<1];
int HEAD[N],NUM_EDGE;
int stack[N],top;
bool cmp(int u,int v) {return DFN[u]<DFN[v];}

void ADD(int u,int v)
{
	if (u==v) return;
	EDGE[++NUM_EDGE].to=v;
	EDGE[NUM_EDGE].next=HEAD[u];
	HEAD[u]=NUM_EDGE;
}

void Insert(int x)
{
	if (top==1) {stack[++top]=x; return;}
	int lca=LCA(x,stack[top]);
	if (lca==stack[top]) {stack[++top]=x; return;}
	while (top>1 && DFN[stack[top-1]]>=DFN[lca])
		 ADD(stack[top-1],stack[top]), top--;
	if (lca!=stack[top]) ADD(lca,stack[top]), stack[top]=lca;
	stack[++top]=x;
}

void Build()
{
	NUM_EDGE=0; stack[top=1]=1;
	for (int i=1; i<=k; ++i) Insert(a[i]);
	while (top>=2) ADD(stack[top-1],stack[top]), top--;
}

void DP(int x)
{
	F[x]=0; G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
	{
		int y=EDGE[i].to; DP(y);
		F[x]+=F[y]; G[x]+=G[y];
	}
	if (!vis[x]) F[x]+=(G[x]>1), G[x]=(G[x]==1);
	else F[x]+=G[x], G[x]=1;
}

void Clear(int x)
{
	vis[x]=false; F[x]=G[x]=0;
	for (int i=HEAD[x]; i; i=EDGE[i].next)
		Clear(EDGE[i].to);
	HEAD[x]=0;
}

int main()
{
//	freopen("data.in","r",stdin);
//	freopen("datam.out","w",stdout);
	scanf("%d",&n);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	DFS(1,0);
	scanf("%d",&m);
	for (int i=1; i<=m; ++i)
	{
		scanf("%d",&k);
		for (int j=1; j<=k; ++j)
			scanf("%d",&a[j]), vis[a[j]]=true;
		sort(a+1,a+k+1,cmp); flag=1;
		for (int j=1; j<=k; ++j)
			if (vis[a[j]] && vis[f[a[j]][0]]) {flag=false; break;}
		Build();
		if (flag) DP(1), printf("%d\n",F[1]);
		else puts("-1");
		Clear(1);
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[y]<dep[st[st[0]-1]])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y||!st[0]) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		if(st[0])
		while(--st[0])
		add(st[st[0]],st[st[0]+1]);
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#pragma GCC optimize(3)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 1000010
using namespace std;
int frt[N],nxt[N*2],v[N*2],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline bool cmp(int x,int y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 1000010
using namespace std;
int frt[N],nxt[N*2],v[N*2],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}