#include <bits/stdc++.h>
using namespace std;
int read() {
  int f, x, c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0');
  while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
  return f ? -x : x;
}
int val[505], n, gy, gx, cnt, head[505 << 1], mar[505 << 1], ret[505 << 1],
    up[505 << 1];
int L, R, maxflow, ans;
struct edge {
  int nxt, to;
} e[505 << 2];
void add(int x, int y) {
  e[++cnt].to = y;
  e[cnt].nxt = head[x];
  head[x] = cnt;
}
void dfs(int x, int f, int top) {
  if (mar[x]) {
    ret[top] -= mar[x];
    ret[x] = mar[x], top = x;
  }
  up[x] = top;
  for (int i = head[x]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (to == f) continue;
    dfs(to, x, top);
  }
}
struct mcmf {
  int cnt, head[505 << 1], S, T, mv[505 << 1], pre[505 << 1], dis[505 << 1],
      vis[505 << 1];
  struct edge {
    int nxt, to, fl, w;
  } e[505 * 10];
  void prep() {
    cnt = -1;
    memset(head, -1, sizeof(head));
  }
  void add(int x, int y, int fl, int w) {
    e[++cnt].to = y;
    e[cnt].fl = fl;
    e[cnt].w = w;
    e[cnt].nxt = head[x];
    head[x] = cnt;
    e[++cnt].to = x;
    e[cnt].fl = 0;
    e[cnt].w = -w;
    e[cnt].nxt = head[y];
    head[y] = cnt;
  }
  int spfa() {
    memset(dis, 127, sizeof(dis));
    memset(vis, 0, sizeof(vis));
    queue<int> q;
    q.push(S);
    vis[S] = 1;
    dis[S] = 0;
    mv[S] = 0x7fffffff;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      vis[now] = 0;
      for (int i = head[now]; i != -1; i = e[i].nxt) {
        int to = e[i].to, fl = e[i].fl, w = e[i].w;
        if (fl && dis[to] > dis[now] + w) {
          dis[to] = dis[now] + w;
          mv[to] = min(fl, mv[now]);
          pre[to] = i;
          if (!vis[to]) {
            vis[to] = 1;
            q.push(to);
          }
        }
      }
    }
    return dis[T] != dis[0];
  }
  void updata() {
    int x = T;
    while (x != S) {
      int i = pre[x];
      e[i].fl -= mv[T];
      e[i ^ 1].fl += mv[T];
      x = e[i ^ 1].to;
    }
    maxflow += mv[T];
    ans += mv[T] * dis[T];
  }
  void EK() {
    while (spfa()) updata();
  }
  void build() {
    S = n * 2 + 1;
    T = n * 2 + 2;
    for (int i = 1; i <= n; i++) {
      if (mar[i]) {
        add(S, i, ret[i], 0), L += ret[i];
        if (ret[i] < 0) {
          printf("-1");
          exit(0);
        }
      }
    }
    for (int i = n + 1; i <= n * 2; i++) {
      if (mar[i]) {
        add(i, T, ret[i], 0), R += ret[i];
        if (ret[i] < 0) {
          printf("-1");
          exit(0);
        }
      }
    }
    for (int i = 1; i <= n; i++) add(up[i], up[i + n], 1, -val[i]);
  }
} A;
int main() {
  A.prep();
  n = read();
  gx = read();
  gy = read() + n;
  for (int i = 1; i <= n; i++) val[i] = read();
  for (int o = 0; o <= 1; o++) {
    for (int x, y, i = 1; i < n; i++) {
      x = read() + o * n;
      y = read() + o * n;
      add(x, y);
      add(y, x);
    }
  }
  for (int k, o = 0; o <= 1; o++) {
    k = read();
    for (int x, y, i = 1; i <= k; i++) {
      x = read();
      y = read();
      mar[o * n + x] = y;
    }
  }
  dfs(gx, 0, 0);
  dfs(gy, 0, 0);
  A.build();
  A.EK();
  if (L != R || L != maxflow || R != maxflow)
    printf("-1");
  else
    printf("%d", -ans);
  return 0;
}
