{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eThere is a tree having $n$ nodes, labeled from 1 to $n$. The root of the tree is always 1, and the depth of a node $p$ is the number of nodes on the shortest path between node $p$ and the root.\u003cbr\u003eIn computer science, the Lowest Common Ancestor (LCA) of two nodes $v$ and $w$ in a tree is the lowest (i.e. deepest) node that has both $v$ and $w$ as descendants, where we define each node to be a descendant of itself (so if $v$ has a direct connection from $w$, $w$ is the lowest common ancestor).\u003cbr\u003eYou have to answer $m$ queries. Each query gives two non-empty node sets $A$ and $B$, there might be some nodes in both sets.\u003cbr\u003eYou should select one node $x$ from set $A$, and one node $y$ from set $B$, $x$ and $y$ can be the same node. Your goal is to maximize the depth of the LCA of $x$ and $y$.\u003cbr\u003ePlease write a program to answer these queries.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains several test cases, no more than 5 test cases.\u003cbr\u003eIn each test case, the first line contains two integers $n(1\\leq n\\leq 100000)$ and $m(1\\leq m\\leq 100000)$, denoting the number of nodes and queries.\u003cbr\u003eFor the next $n-1$ lines,each line contians two integers $a$ and $b$, denoting a bi-directional edge between node $a$ and $b$.\u003cbr\u003eThen there are $2m$ lines, every two lines describes one query.\u003cbr\u003eFor each query, the first line describes the set A.\u003cbr\u003eThe first integer $k(1\\leq k\\leq n)$ denotes the number of nodes in set $A$, and the next $k$ integers describing the nodes in set $A$. There might be some nodes appear multiple times in the set.\u003cbr\u003eThe second line describes the set $B$ in the same format of set $A$.\u003cbr\u003e\u003cbr\u003eIt is guaranteed that $\\sum k\\leq 100000$ in each test case.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For every query, print a number denoting the answer, which means the maximum depth of the LCA."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7 3\r\n1 2\r\n1 3\r\n3 4\r\n3 5\r\n4 6\r\n4 7\r\n1 6\r\n1 7\r\n2 6 7\r\n1 7\r\n2 5 4\r\n2 3 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n4\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}