#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 2e6 + 10;
const int INF = 0x3f3f3f3f;
int n, ans, in, out, Q, a[N];
int read() {
  int ret = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) ret = ret * 10 + (c ^ 48), c = getchar();
  return ret;
}
void failed() {
  puts("-1");
  exit(0);
}
namespace Flow {
int S = 0, T = N - 5, tot = 1, mxflow;
int head[N], fr[N], dis[N], inq[N], ins[N];
queue<int> q;
struct Tway {
  int u, v, nex, w, c;
  Tway(int _u = 0, int _v = 0, int _nex = 0, int _w = 0, int _c = 0)
      : u(_u), v(_v), nex(_nex), w(_w), c(_c) {}
} e[M];
void addedege(int u, int v, int w, int c) {
  e[++tot] = Tway(u, v, head[u], w, c);
  head[u] = tot;
  e[++tot] = Tway(v, u, head[v], 0, -c);
  head[v] = tot;
}
bool spfa() {
  memset(dis, -0x3f, (T + 2) << 2);
  memset(inq, 0, (T + 2) << 2);
  dis[S] = 0;
  q.push(S);
  inq[S] = 1;
  fr[T] = -1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = head[u]; i; i = e[i].nex) {
      int v = e[i].v;
      if (e[i].w && dis[u] + e[i].c > dis[v]) {
        dis[v] = dis[u] + e[i].c;
        fr[v] = i;
        if (!inq[v]) q.push(v), inq[v] = 1;
      }
    }
  }
  return ~fr[T];
}
void mcfx() {
  while (spfa()) {
    int mi = INF;
    for (int i = fr[T]; i; i = fr[e[i].u]) mi = min(mi, e[i].w);
    for (int i = fr[T]; i; i = fr[e[i].u])
      ans += e[i].c * mi, e[i].w -= mi, e[i ^ 1].w += mi;
    mxflow += mi;
  }
}
}  // namespace Flow
namespace Tree {
struct Tway {
  int v, nex;
};
struct Tree {
  int rt, tot, b[N], bl[N], head[N];
  Tway e[N << 1];
  vector<int> vec[N];
  void add(int u, int v) {
    e[++tot] = (Tway){v, head[u]};
    head[u] = tot;
    e[++tot] = (Tway){u, head[v]};
    head[v] = tot;
  }
  int dfs(int x, int fa, bool f) {
    int sum = 0;
    vec[x].push_back(x);
    for (int i = head[x]; i; i = e[i].nex) {
      int v = e[i].v;
      if (v == fa) continue;
      sum += dfs(v, x, f);
      for (int i = 0; i < (int)vec[v].size(); ++i) vec[x].push_back(vec[v][i]);
    }
    if (b[x]) {
      if (b[x] < sum) failed();
      if (!f)
        Flow::addedege(Flow::S, x, b[x] - sum, 0), in += b[x] - sum;
      else
        Flow::addedege(x + n, Flow::T, b[x] - sum, 0), out += b[x] - sum;
      for (int i = 0; i < (int)vec[x].size(); ++i) bl[vec[x][i]] = x;
      vec[x].clear();
      return b[x];
    }
    return sum;
  }
} T[2];
}  // namespace Tree
using namespace Tree;
int main() {
  n = read();
  T[0].rt = read();
  T[1].rt = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i < n; ++i) T[0].add(read(), read());
  for (int i = 1; i < n; ++i) T[1].add(read(), read());
  Q = read();
  for (int i = 1, x; i <= Q; ++i) x = read(), T[0].b[x] = read();
  Q = read();
  for (int i = 1, x; i <= Q; ++i) x = read(), T[1].b[x] = read();
  T[0].dfs(T[0].rt, 0, 0);
  T[1].dfs(T[1].rt, 0, 1);
  for (int i = 1; i <= n; ++i)
    Flow::addedege(T[0].bl[i], T[1].bl[i] + n, 1, a[i]);
  if (in ^ out) failed();
  Flow::mcfx();
  if (Flow::mxflow ^ in) failed();
  printf("%d\n", ans);
  return 0;
}
