#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, S, T, ans, sd;
int d[1111], w[555], lim[2][555], tp[2][555];
bool vis[1111];
struct edge {
  int t, w, c;
};
vector<edge> e;
vector<int> adj[1111], ee[2][555];
queue<int> Q;
void Add(int a, int b, int c, int d) {
  e.push_back((edge){b, c, d}), adj[a].push_back(((int)e.size() - 1));
  e.push_back((edge){a, 0, -d}), adj[b].push_back(((int)e.size() - 1));
}
bool Spfa() {
  memset(d, 0x3f, sizeof d);
  d[S] = 0;
  memset(vis, 0, sizeof vis);
  Q.push(S);
  while (!Q.empty()) {
    int u = Q.front(), v;
    Q.pop();
    vis[u] = 0;
    for (int i = (0); i <= (((int)adj[u].size() - 1)); ++i) {
      edge E = e[adj[u][i]];
      if (E.w && d[v = E.t] > d[u] + E.c) {
        d[v] = d[u] + E.c;
        if (!vis[v]) Q.push(v), vis[v] = 1;
      }
    }
  }
  return d[T] != INF;
}
int Dfs(int u, int re) {
  vis[u] = 1;
  if (u == T) return re;
  int w = 0, tmp, v;
  for (int i = (0); i <= (((int)adj[u].size() - 1)); ++i) {
    edge& E = e[adj[u][i]];
    if (vis[v = E.t] || !E.w || d[v] != d[u] + E.c) continue;
    tmp = Dfs(v, min(re - w, E.w));
    ans += tmp * E.c, E.w -= tmp, e[adj[u][i] ^ 1].w += tmp, w += tmp;
    if (w == re) break;
  }
  return w;
}
int Mcmf() {
  int flw = 0;
  while (Spfa()) {
    do {
      memset(vis, 0, sizeof vis);
      flw += Dfs(S, INF);
    } while (vis[T]);
  }
  return flw;
}
int Dfs(int u, int fa, int top) {
  int tot = 0;
  if (lim[sd][u]) top = u;
  tp[sd][u] = top;
  for (int i = (0); i <= (((int)ee[sd][u].size() - 1)); ++i) {
    int v = ee[sd][u][i];
    if (v == fa) continue;
    tot += Dfs(v, u, top);
  }
  if (lim[sd][u]) {
    int tmp = lim[sd][u];
    lim[sd][u] -= tot;
    if (lim[sd][u] < 0) cout << "-1\n", exit(0);
    tot = tmp;
  }
  return tot;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int rt[2];
  cin >> n >> rt[0] >> rt[1];
  for (int i = (1); i <= (n); ++i) cin >> w[i];
  for (int num = (0); num <= (1); ++num) {
    sd = num;
    for (int i = (2); i <= (n); ++i) {
      int x, y;
      cin >> x >> y;
      ee[sd][x].push_back(y), ee[sd][y].push_back(x);
    }
  }
  for (int num = (0); num <= (1); ++num) {
    sd = num;
    int m;
    cin >> m;
    for (int i = (1); i <= (m); ++i) {
      int x, y;
      cin >> x >> y;
      lim[sd][x] = y;
    }
    Dfs(rt[sd], 0, rt[sd]);
  }
  int flw[2] = {0};
  for (int num = (0); num <= (1); ++num) {
    sd = num;
    for (int i = (1); i <= (n); ++i) flw[sd] += lim[sd][i];
  }
  if (flw[0] != flw[1]) cout << "-1\n", exit(0);
  T = n << 1 | 1;
  for (int i = (1); i <= (n); ++i)
    if (lim[0][i]) Add(S, i, lim[0][i], 0);
  for (int i = (1); i <= (n); ++i)
    if (lim[1][i]) Add(i + n, T, lim[1][i], 0);
  for (int i = (1); i <= (n); ++i) Add(tp[0][i], tp[1][i] + n, 1, -w[i]);
  int flow = Mcmf();
  if (flow != flw[1])
    cout << "-1\n";
  else
    cout << -ans << '\n';
  return 0;
}
