#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> operator+(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<long long, long long> operator-(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<long long, long long> operator*(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return make_pair(a.first * b.first, a.second * b.second);
}
pair<long long, long long> operator%(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return make_pair(a.first % b.first, a.second % b.second);
}
template <class T>
inline T lowbit(T x) {
  return x & (-x);
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 510 * 2;
struct tree {
  struct edge {
    int v, nxt;
  } g[N * 2];
  int head[N], sz;
  void add(int u, int v) {
    g[++sz].v = v;
    g[sz].nxt = head[u];
    head[u] = sz;
  }
  void adde() {
    int u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  int col[N], w[N];
  long long calc(int u, int p) {
    long long sum = 0;
    int v;
    for (int i = head[u]; i; i = g[i].nxt)
      if ((v = g[i].v) != p) sum += calc(v, u);
    if (w[u]) w[u] -= sum;
    if (w[u] < 0) {
      printf("-1");
      exit(0);
    }
    return w[u] + sum;
  }
  void dfs(int u, int p, int lst) {
    if (w[u]) lst = u;
    col[u] = lst;
    int v;
    for (int i = head[u]; i; i = g[i].nxt)
      if ((v = g[i].v) != p) dfs(v, u, lst);
  }
} t1, t2;
namespace flow {
struct edge {
  int v, nxt, cap;
  long long w;
} g[N * 4];
int head[N], sz = 1;
void _add(int u, int v, int cap, int w) {
  g[++sz].nxt = head[u];
  head[u] = sz;
  g[sz].w = w;
  g[sz].v = v;
  g[sz].cap = cap;
}
void add(int u, int v, int cap, int w) {
  _add(u, v, cap, w);
  _add(v, u, 0, -w);
}
int q[N], pre[N];
bool inq[N];
long long d[N];
bool spfa(int s, int dest) {
  fill(d, d + dest + 1, (long long)0x3f3f3f3f);
  fill(pre, pre + dest + 1, 0);
  q[0] = s;
  d[s] = 0;
  inq[s] = 1;
  for (int h = 0, t = 1, u, v; h != t; h = (h + 1) % N, inq[u] = 0)
    for (int i = head[u = q[h]]; i; i = g[i].nxt)
      if (g[i].cap && d[v = g[i].v] > d[u] + g[i].w) {
        d[v] = d[u] + g[i].w;
        pre[v] = i;
        if (!inq[v]) inq[v] = 1, q[t++] = v, t %= N;
      }
  return d[dest] != (long long)0x3f3f3f3f;
}
pair<long long, long long> mf(int s, int t) {
  long long ret = 0, f = 0;
  while (spfa(s, t)) {
    int tmp = (long long)0x3f3f3f3f;
    long long sum = 0;
    for (int i = pre[t]; i; i = pre[g[i ^ 1].v])
      tmp = min(tmp, g[i].cap), sum += g[i].w;
    ret += tmp * sum;
    f += tmp;
    for (int i = pre[t]; i; i = pre[g[i ^ 1].v])
      g[i].cap -= tmp, g[i ^ 1].cap += tmp;
  }
  return make_pair(f, ret);
}
}  // namespace flow
int n;
long long a[N];
int main() {
  n = read();
  int u1 = read(), u2 = read();
  for (int i = (1); i <= (n); i++) a[i] = read();
  for (int i = (1); i <= (n - 1); i++) t1.adde();
  for (int i = (1); i <= (n - 1); i++) t2.adde();
  int q1 = read();
  for (int i = (1); i <= (q1); i++) {
    int k = read(), x = read();
    t1.w[k] = x;
  }
  int q2 = read();
  for (int i = (1); i <= (q2); i++) {
    int k = read(), x = read();
    t2.w[k] = x;
  }
  if (t1.w[u1] != t2.w[u2]) {
    printf("-1");
    return 0;
  }
  int tot = t1.w[u1];
  t1.dfs(u1, 0, 0);
  t1.calc(u1, 0);
  t2.dfs(u2, 0, 0);
  t2.calc(u2, 0);
  int S = 2 * n + 1, T = 2 * n + 2;
  for (int i = (1); i <= (n); i++)
    if (t1.w[i]) flow::add(S, i, t1.w[i], 0);
  for (int i = (1); i <= (n); i++)
    if (t2.w[i]) flow::add(i + n, T, t2.w[i], 0);
  for (int i = (1); i <= (n); i++)
    flow::add(t1.col[i], t2.col[i] + n, 1, -a[i]);
  pair<long long, long long> res = flow::mf(S, T);
  if (res.first != tot)
    printf("-1");
  else
    printf("%I64d", -res.second);
}
