#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 10;
int n, w[maxn], ans;
namespace dinic {
const int maxn = 5e2 * 2 + 10, maxm = 5e2 * 6 + 10;
int s, t;
int ecnt, ebeg[maxn], enxt[maxm], eto[maxm], ecap[maxm], ew[maxm];
int dis[maxn], pre[maxn];
bool inq[maxn];
void init() {
  ecnt = 1;
  s = 2 * n + 1;
  t = s + 1;
}
void adde(int u, int v, int c, int w) {
  ++ecnt;
  enxt[ecnt] = ebeg[u];
  ebeg[u] = ecnt;
  eto[ecnt] = v;
  ecap[ecnt] = c;
  ew[ecnt] = w;
}
void ae(int u, int v, int c, int w) {
  adde(u, v, c, w);
  adde(v, u, 0, -w);
}
int run() {
  for (int i = 1; i <= t; ++i) dis[i] = -1e9;
  dis[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int pos = q.front();
    q.pop();
    inq[pos] = false;
    for (int i = ebeg[pos]; i; i = enxt[i])
      if (ecap[i] && dis[eto[i]] < dis[pos] + ew[i]) {
        dis[eto[i]] = dis[pos] + ew[i];
        pre[eto[i]] = i;
        if (!inq[eto[i]]) {
          inq[eto[i]] = true;
          q.push(eto[i]);
        }
      }
  }
  if (dis[t] == -1e9) return 0;
  for (int p = t; p != s; p = eto[pre[p] ^ 1]) {
    ans += ew[pre[p]];
    --ecap[pre[p]];
    ++ecap[pre[p] ^ 1];
  }
  return 1;
}
}  // namespace dinic
struct tree {
  vector<int> g[maxn];
  int root, fa[maxn], tot;
  int x[maxn];
  void dfs(int pos) {
    for (int i = 0; i < g[pos].size(); ++i)
      if (g[pos][i] != fa[pos]) {
        fa[g[pos][i]] = pos;
        dfs(g[pos][i]);
      }
  }
  void init() {
    for (int i = 1, u, v; i < n; ++i) {
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(root);
  }
  int dfs(int pos, bool rt) {
    if (!rt && ~x[pos]) return x[pos];
    int res = 0;
    for (int i = 0; i < g[pos].size(); ++i)
      if (g[pos][i] != fa[pos]) res += dfs(g[pos][i], false);
    return res;
  }
  void work(bool id) {
    int q;
    scanf("%d", &q);
    for (int i = 1; i <= n; ++i) x[i] = -1;
    while (q--) {
      int a, b;
      scanf("%d%d", &a, &b);
      x[a] = b;
      if (a == root) tot = b;
    }
    for (int i = 1; i <= n; ++i)
      if (~x[i]) {
        int xx = x[i] - dfs(i, true);
        if (xx < 0) {
          puts("-1");
          exit(0);
        }
        if (id)
          dinic::ae(n + i, dinic::t, xx, 0);
        else
          dinic::ae(dinic::s, i, xx, 0);
      }
  }
} t[2];
int main() {
  scanf("%d%d%d", &n, &t[0].root, &t[1].root);
  for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
  dinic::init();
  t[0].init();
  t[1].init();
  t[0].work(false);
  t[1].work(true);
  for (int i = 1; i <= n; ++i) {
    int p = i, q = i;
    while (t[0].x[p] == -1) p = t[0].fa[p];
    while (t[1].x[q] == -1) q = t[1].fa[q];
    dinic::ae(p, n + q, 1, w[i]);
  }
  int cnt = 0;
  while (dinic::run()) ++cnt;
  if (cnt != t[0].tot || cnt != t[1].tot)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
