#include <bits/stdc++.h>
using namespace std;
int x, n, y, w[510], u, v, a, b, S, T, flag, q0, q1;
namespace MCF {
int tot = 1, Head[5010], Next[100010], From[100010], To[100010], Cost[100010],
    Val[100010];
int FLOW, Q[50100], pre[5010], dis[5010];
bool inq[5010];
void _addedge(int u, int v, int w, int c) {
  tot++;
  Next[tot] = Head[u];
  Head[u] = tot;
  From[tot] = u;
  To[tot] = v;
  Cost[tot] = c;
  Val[tot] = w;
}
int addedge(int u, int v, int w, int c) {
  _addedge(u, v, w, c);
  _addedge(v, u, 0, -c);
  return tot - 1;
}
int calc() {
  int res = 0, flow = 0x3f3f3f3f;
  for (int it = T; pre[it]; it = From[pre[it]]) flow = min(flow, Val[pre[it]]);
  FLOW += flow;
  for (int it = T; pre[it]; it = From[pre[it]]) {
    Val[pre[it]] -= flow;
    Val[pre[it] ^ 1] += flow;
    res += flow * Cost[pre[it]];
  }
  return res;
}
bool spfa() {
  int h = 0, t = 1;
  Q[1] = S;
  memset(pre, 0, sizeof pre);
  memset(inq, 0, sizeof inq);
  for (int i = 1; i <= T; i++) dis[i] = -1000000000;
  inq[S] = true;
  dis[S] = 0;
  while (t != h) {
    h++;
    if (h == 2 * T) h = 1;
    int u = Q[h];
    inq[u] = false;
    for (int it = Head[u]; it; it = Next[it]) {
      int v = To[it];
      if (Val[it] > 0 && dis[v] < dis[u] + Cost[it]) {
        dis[v] = Cost[it] + dis[u];
        pre[v] = it;
        if (!inq[v]) {
          inq[v] = true;
          t++;
          if (t == 2 * T) t = 1;
          Q[t] = v;
        }
      }
    }
  }
  return pre[T] != 0;
}
int mcf() {
  int res = 0;
  while (spfa()) res += calc();
  return res;
}
}  // namespace MCF
struct TREE {
  int cnt, Head[510], Next[510 << 1], To[510 << 1];
  int lim[510], haslim[510], id, chk[510], p[510], olim[510];
  void addedge(int u, int v) {
    cnt++;
    Next[cnt] = Head[u];
    Head[u] = cnt;
    To[cnt] = v;
  }
  void addlim(int a, int b) {
    haslim[a] = 1;
    olim[a] = lim[a] = b;
  }
  void build(int x, int fa, int source) {
    for (int it = Head[x]; it; it = Next[it]) {
      int v = To[it];
      if (v != fa) build(v, x, haslim[x] ? x : source);
    }
    if (haslim[x]) {
      if (source != x) lim[source] -= olim[x];
      source = x;
      if (id == 1)
        chk[x] = MCF::addedge(S, source + n, lim[source], 0);
      else
        chk[x] = MCF::addedge(source + 2 * n, T, lim[source], 0);
    }
    if (id == 1)
      p[x] = MCF::addedge(source + n, x, 1, w[x]);
    else
      p[x] = MCF::addedge(x, source + 2 * n, 1, 0);
  }
  void check(int &flag) {
    for (int i = 1; i <= n; i++)
      if (haslim[i] && MCF::Val[chk[i]] != 0) {
        flag = 0;
        break;
      }
  }
} Tree[3];
int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    Tree[1].addedge(u, v);
    Tree[1].addedge(v, u);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    Tree[2].addedge(u, v);
    Tree[2].addedge(v, u);
  }
  scanf("%d", &q0);
  for (int i = 1; i <= q0; i++) {
    scanf("%d%d", &a, &b);
    Tree[1].addlim(a, b);
  }
  scanf("%d", &q1);
  for (int i = 1; i <= q1; i++) {
    scanf("%d%d", &a, &b);
    Tree[2].addlim(a, b);
  }
  Tree[1].id = 1;
  Tree[2].id = 2;
  S = n * 3 + 1, T = n * 3 + 2;
  Tree[1].build(x, x, x);
  Tree[2].build(y, y, y);
  int cost = MCF::mcf();
  flag = 1;
  Tree[1].check(flag), Tree[2].check(flag);
  if (flag)
    printf("%d\n", cost);
  else
    printf("-1\n");
}
