#include <bits/stdc++.h>
using namespace std;
long long dist[1011], vist[1011], pre[1011], fa[1011], fl[1011], que[1011 * 10],
    max_flw, max_cost, tot, S, T, indexx[1011];
long long top[2][1011], lim[2][1011], sum[2][1011], n, val[1011], root[2], Q[2],
    In, Out;
vector<long long> Map[2][1011];
struct apple {
  long long v, nxt, flw, q;
} edge[1011 * 10];
void addedge(long long x, long long y, long long flw, long long z) {
  edge[++tot].v = y;
  edge[tot].flw = flw;
  edge[tot].q = z;
  edge[tot].nxt = indexx[x];
  indexx[x] = tot;
}
void add(long long x, long long y, long long flw, long long z) {
  addedge(x, y, flw, z);
  addedge(y, x, 0, -z);
  if (x == S) Out += flw;
  if (y == T) In += flw;
}
long long spfa() {
  for (long long i = 1; i <= T; i++) dist[i] = -0x7f7f7f7f;
  memset(vist, 0, sizeof(vist));
  memset(pre, 0, sizeof(pre));
  memset(fa, 0, sizeof(fa));
  memset(fl, 0, sizeof(fl));
  long long head = 0, tail = 0, x, t, vv, qq;
  que[++tail] = S;
  fl[S] = 0x7f7f7f7f;
  dist[S] = 0;
  while (head < tail) {
    x = que[++head];
    t = indexx[x];
    while (t) {
      vv = edge[t].v;
      qq = edge[t].q;
      if (dist[vv] < dist[x] + qq && edge[t].flw) {
        dist[vv] = dist[x] + qq;
        pre[vv] = t;
        fa[vv] = x;
        fl[vv] = min(fl[x], edge[t].flw);
        if (!vist[vv]) {
          vist[vv] = 1;
          que[++tail] = vv;
        }
      }
      t = edge[t].nxt;
    }
    vist[x] = 0;
  }
  return fl[T];
}
void EK() {
  long long x;
  while (spfa()) {
    x = T;
    max_flw += fl[T];
    max_cost += fl[T] * dist[T];
    while (x != S) {
      edge[pre[x]].flw -= fl[T];
      edge[((pre[x] - 1) ^ 1) + 1].flw += fl[T];
      x = fa[x];
    }
  }
}
void dfs(long long u, long long k, long long anc, long long f) {
  if (lim[k][u]) anc = u;
  top[k][u] = anc;
  sum[k][u] = 0;
  long long vv;
  long long len = Map[k][u].size();
  for (long long i = 0; i < len; i++) {
    vv = Map[k][u][i];
    if (vv != f) {
      dfs(vv, k, anc, u);
      sum[k][u] += (lim[k][vv] == 0 ? sum[k][vv] : lim[k][vv]);
    }
  }
}
void build() {
  S = n * 2 + 1, T = n * 2 + 2;
  for (long long i = 1; i <= n; i++) {
    if (lim[0][i] > sum[0][i]) add(S, (i + 0 * n), lim[0][i] - sum[0][i], 0);
    if (lim[1][i] > sum[1][i]) add((i + 1 * n), T, lim[1][i] - sum[1][i], 0);
    add((top[0][i] + 0 * n), (top[1][i] + 1 * n), 1, val[i]);
  }
}
signed main() {
  long long x, y;
  scanf("%lld%lld%lld", &n, &root[0], &root[1]);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
  }
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    Map[0][x].push_back(y);
    Map[0][y].push_back(x);
  }
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    Map[1][x].push_back(y);
    Map[1][y].push_back(x);
  }
  scanf("%lld", &Q[0]);
  for (long long i = 1; i <= Q[0]; i++) {
    scanf("%lld%lld", &x, &y);
    lim[0][x] = y;
  }
  scanf("%lld", &Q[1]);
  for (long long i = 1; i <= Q[1]; i++) {
    scanf("%lld%lld", &x, &y);
    lim[1][x] = y;
  }
  dfs(root[0], 0, 0, 0);
  dfs(root[1], 1, 0, 0);
  build();
  EK();
  long long t = indexx[S];
  while (t) {
    if (edge[t].flw) {
      printf("-1");
      return 0;
    }
    t = edge[t].nxt;
  }
  t = indexx[T];
  while (t) {
    if (edge[((t - 1) ^ 1) + 1].flw) {
      printf("-1");
      return 0;
    }
    t = edge[t].nxt;
  }
  if (In != Out || max_flw != Out) {
    printf("-1\n");
  } else
    printf("%lld", max_cost);
  return 0;
}
