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

local function getor(x, y)
  if x == 0 then return y end
  if y == 0 then return x end
  local ret = 0
  local mul = 1
  while 0 < x or 0 < y do
    if 1 <= (x % 2) + (y % 2) then
      ret = ret + mul
    end
    x, y, mul = mfl(x / 2), mfl(y / 2), mul * 2
  end
  return ret
end
-- print(getor(1, 7)) os.exit()

local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage = 1
  while right - left + 1 < self.size[start_stage] do
    start_stage = start_stage + 1
  end
  local ret = self.emptyvalue
  local t1, t2, t3 = {start_stage}, {left}, {right}
  while 0 < #t1 do
    local stage, l, r = t1[#t1], t2[#t1], t3[#t1]
    table.remove(t1) table.remove(t2) table.remove(t3)
    local sz = self.size[stage]
    if (l - 1) % sz ~= 0 then
      local newr = mmi(r, mce((l - 1) / sz) * sz)
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, newr)
      l = newr + 1
    end
    if sz <= r + 1 - l then
      ret = self.func(ret, self.stage[stage][mce(l / sz)])
      l = l + sz
    end
    if l <= r then
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, r)
    end
  end
  return ret
end
SegTree.setValue = function(self, idx, value, silent)
  self.stage[self.stagenum][idx] = value
  if not silent then
    for i = self.stagenum - 1, 1, -1 do
      local dst = mce(idx / 2)
      local rem = dst * 4 - 1 - idx
      self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
      idx = dst
    end
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

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 st = SegTree.new(2 * n - 1, function(a, b)
  return len[a] < len[b] and a or b end,
  n + 1
)

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)
  st:setValue(#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 stLine = SegTree.new(2 * n - 2, function(a, b) return a + b end, 0)

local m = io.read("*n")
local mtot = 2^m
local mbox = {}
for i = 1, mtot do
  mbox[i] = 0
end
mbox[1] = 1
local mu, mv = {}, {}
for i = 1, m do
  mu[i], mv[i] = io.read("*n", "*n")
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

for il = 1, n - 1 do
  local lx, ly = line[il][1], line[il][2]
  local p1, p2 = linepos[il][1], linepos[il][2]
  stLine:setValue(p1, 1)
  stLine:setValue(p2, -1)
  local mul = 1
  local actsum = 0
  for im = 1, m do
    local u, v = mu[im], mv[im]
    local pu, pv = posinv[u], posinv[v]
    if pv < pu then pu, pv = pv, pu end
    local parent = st:getRange(pu, pv)
    local activate = false
    local pp = posinv[parent]
    if pv < pp then
      activate = 1 == stLine:getRange(pv, pp - 1)
    elseif pp < pv then
      activate = 1 == stLine:getRange(pp, pv - 1)
    end
    if not activate then
      if pu < pp then
        activate = 1 == stLine:getRange(pu, pp - 1)
      elseif pp < pu then
        activate = 1 == stLine:getRange(pp, pu - 1)
      end
    end
    if activate then
      actsum = actsum + mul
    end
    mul = mul * 2
  end
  if 0 < actsum then
  end
  -- print("IL", il, actsum)
  for im = mtot, 1, -1 do
    local src = im - 1
    local dst = getor(src, actsum)
    -- print("a " .. src .. " " .. dst)
    mbox[dst + 1] = mbox[dst + 1] + mbox[src + 1]
  end
  stLine:setValue(p1, 0)
  stLine:setValue(p2, 0)
  -- print(table.concat(mbox, " "))
end
-- print(table.concat(mbox, " "))
print(mbox[mtot])
