#include <bits/stdc++.h>
inline int read() {
  char c = getchar();
  int x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
const int N = 5e2 + 5, inf = 2e9;
int n, rt0, rt1, val[N], q0, q1, p0[N], p1[N], ss, tt, flag;
int h[N * 2], edge_cnt = 1, d[N * 2], inq[N * 2], p[N * 2], cost, flow;
struct Edge {
  int to, nex, f, w;
} e[N * 10];
inline void add_edge(int u, int v, int f, int w) {
  e[++edge_cnt] = (Edge){v, h[u], f, w};
  h[u] = edge_cnt;
  e[++edge_cnt] = (Edge){u, h[v], 0, -w};
  h[v] = edge_cnt;
}
bool bellman_fold() {
  for (int u = 1; u <= tt; ++u) d[u] = inf;
  std::queue<int> Q;
  d[ss] = 0;
  Q.push(ss);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    inq[u] = 0;
    for (int i = h[u], v; i; i = e[i].nex)
      if (e[i].f) {
        if (d[v = e[i].to] > d[u] + e[i].w) {
          d[v] = d[u] + e[i].w;
          p[v] = i;
          if (!inq[v]) Q.push(v), inq[v] = 1;
        }
      }
  }
  if (d[tt] == inf) return false;
  for (int u = tt; u != ss; u = e[p[u] ^ 1].to) {
    --e[p[u]].f;
    ++e[p[u] ^ 1].f;
  }
  cost += d[tt];
  ++flow;
  return true;
}
struct Graph {
  int h[N], edge_cnt, lim[N], id[N], fa[N];
  struct Edge {
    int to, nex;
  } e[N << 1];
  inline void add_edge(int u, int v) {
    e[++edge_cnt] = (Edge){v, h[u]};
    h[u] = edge_cnt;
    e[++edge_cnt] = (Edge){u, h[v]};
    h[v] = edge_cnt;
  }
  int dfs(int u, int pre) {
    fa[u] = pre;
    int res = 0;
    for (int i = h[u]; i; i = e[i].nex) {
      int v = e[i].to;
      if (v == pre) continue;
      res += dfs(v, u);
    }
    if (lim[u] != -1) {
      int tmp = lim[u];
      lim[u] -= res;
      if (lim[u] < 0) flag = 1;
      return tmp;
    } else
      return res;
  }
} g0, g1;
int main() {
  n = read();
  rt0 = read();
  rt1 = read();
  for (int i = 1; i <= n; ++i) val[i] = read();
  for (int i = 1; i < n; ++i) g0.add_edge(read(), read());
  for (int i = 1; i < n; ++i) g1.add_edge(read(), read());
  memset(g0.lim, -1, sizeof(g0.lim));
  memset(g1.lim, -1, sizeof(g1.lim));
  q0 = read();
  for (int i = 1, u; i <= q0; ++i) {
    g0.id[p0[i] = read()] = i;
    g0.lim[p0[i]] = read();
  }
  q1 = read();
  for (int i = 1, u; i <= q1; ++i) {
    g1.id[p1[i] = read()] = i;
    g1.lim[p1[i]] = read();
  }
  if (g0.lim[rt0] != g1.lim[rt1])
    puts("-1");
  else {
    int sum = g0.lim[rt0];
    g0.dfs(rt0, 0);
    g1.dfs(rt1, 0);
    ss = n + n + 1;
    tt = ss + 1;
    if (flag)
      puts("-1");
    else {
      for (int i = 1; i <= q0; ++i) add_edge(ss, p0[i], g0.lim[p0[i]], 0);
      for (int i = 1; i <= q1; ++i) add_edge(n + p1[i], tt, g1.lim[p1[i]], 0);
      for (int i = 1; i <= n; ++i) {
        if (!g0.id[i]) add_edge(g0.fa[i], i, inf, 0);
        if (!g1.id[i]) add_edge(n + i, n + g1.fa[i], inf, 0);
        add_edge(i, n + i, 1, -val[i]);
      }
      while (bellman_fold())
        ;
      if (flow != sum)
        puts("-1");
      else
        printf("%d\n", -cost);
    }
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
