local mfl, mce, mmi = math.floor, math.ceil, math.min
local bor = bit.bor

local n = io.read("*n")
local edge = {}
local asked = {}
local cpos = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  asked[i] = false
  cpos[i] = 0
  len[i] = 0
end
len[n + 1] = 100
local line = {}
for i = 1, n - 1 do
  local x, y = io.read("*n", "*n")
  table.insert(edge[x], y)
  table.insert(edge[y], x)
  line[i] = {x, y}
end

local tasks = {1}
local posinv = {}
for i = 1, n do
  posinv[i] = 0
end
local eulers = {}
while 0 < #tasks do
  local src = tasks[#tasks]
  table.remove(tasks)
  asked[src] = true
  table.insert(eulers, src)
  if posinv[src] == 0 then
    posinv[src] = #eulers
  end
  while cpos[src] < #edge[src] do
    cpos[src] = cpos[src] + 1
    local dst = edge[src][cpos[src]]
    if not asked[dst] then
      len[dst] = len[src] + 1
      table.insert(tasks, src)
      table.insert(tasks, dst)
      break
    end
  end
end
local lca = {}
for i = 1, #eulers do
  lca[i] = {}
  local prv = eulers[i]
  lca[i][1] = prv
  for j = i + 1, #eulers do
    lca[i][j - i + 1] = len[prv] < len[eulers[j]] and prv or eulers[j]
    prv = lca[i][j - i + 1]
  end
end

local m = io.read("*n")
local mtot = 2^m

local posu, posv, posp = {}, {}, {}
for i = 1, m do
  local u, v = io.read("*n", "*n")
  local pu, pv = posinv[u], posinv[v]
  if pv < pu then pu, pv = pv, pu end
  local p = lca[pu][pv - pu + 1]
  posu[i], posv[i], posp[i] = pu, pv, posinv[p]
end
local linepos = {}
for il = 1, n - 1 do
  linepos[il] = {}
  local lx, ly = line[il][1], line[il][2]
  for j = 1, #eulers - 1 do
    if lx == eulers[j] and ly == eulers[j + 1] then
      table.insert(linepos[il], j)
    elseif ly == eulers[j] and lx == eulers[j + 1] then
      table.insert(linepos[il], j)
    end
  end
end
local lineval = {}
for i = 1, 2 * n - 2 do
  lineval[i] = 0
end
local linesum = {}
for i = 1, 2 * n - 2 do
  linesum[i] = {}
end
local function recalc_linesum()
  for i = 1, 2 * n - 2 do
    linesum[i][1] = lineval[i]
    for j = i + 1, 2 * n - 2 do
      linesum[i][j - i + 1] = linesum[i][j - i] + lineval[j]
    end
  end
end

local mbox1, mbox2 = {}, {}
for i = 1, mtot do
  mbox1[i], mbox2[i] = 0, 0
end
mbox1[1] = 1
local function addmbox(src, dst)
  mbox2[dst] = mbox2[dst] + mbox2[src]
  mbox1[dst] = mbox1[dst] + mbox1[src]
  if 1000000000 <= mbox1[dst] then
    mbox1[dst] = mbox1[dst] - 1000000000
    mbox2[dst] = mbox2[dst] + 1
  end
end

for il = 1, n - 1 do
  local lx, ly = line[il][1], line[il][2]
  local p1, p2 = linepos[il][1], linepos[il][2]
  lineval[p1] = 1
  lineval[p2] = -1
  recalc_linesum()
  local mul = 1
  local actsum = 0
  for im = 1, m do
    local pu, pv, pp = posu[im], posv[im], posp[im]
    if pv < pp then
      activate = 0 ~= linesum[pv][pp - pv]
    elseif pp < pv then
      activate = 0 ~= linesum[pp][pv - pp]
    end
    if not activate then
      if pu < pp then
        activate = 0 ~= linesum[pu][pp - pu]
      elseif pp < pu then
        activate = 0 ~= linesum[pp][pu - pp]
      end
    end
    if activate then
      actsum = actsum + mul
    end
    mul = mul * 2
  end
  for im = mtot, 1, -1 do
    local dst = bor(im - 1, actsum)
    addmbox(im, dst + 1)
  end
  lineval[p1] = 0
  lineval[p2] = 0
end
if mbox2[mtot] == 0 then
  print(mbox1[mtot])
else
  local z = 1000000000 + mbox1[mtot]
  local zstr = tostring(z)
  zstr = zstr:sub(2, #zstr)
  print(mbox2[mtot] .. zstr)
end


Measured memory_bytes: 18556