#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int nINF = 1 << 31;
const int MAXN = 2010;
const int INF = 1000000000;
class node {
 public:
  int v, f, couple;
  pair<int, int> w;
  node(int V, pair<int, int> W, int F, int CC) {
    v = V;
    w = W;
    f = F;
    couple = CC;
  };
};
int fa[MAXN], ff[MAXN];
vector<node> g[MAXN];
void newnode(int a, int b, int c, pair<int, int> d) {
  node p(b, d, c, g[b].size());
  node q(a, {-d.first, -d.second}, 0, g[a].size());
  g[a].push_back(p);
  g[b].push_back(q);
}
pair<int, int> SPFA(int s, int t, int n) {
  vector<pair<int, int> > d(n + 1, {INF, INF});
  vector<bool> z(n + 1, false);
  d[s] = {0, 0};
  queue<int> q;
  q.push(s);
  z[s] = true;
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (auto p = g[i].begin(); p != g[i].end(); ++p) {
      pair<int, int> dc = {d[i].first + p->w.first, d[i].second + p->w.second};
      if (p->f > 0 && d[p->v] > dc) {
        d[p->v] = dc;
        fa[p->v] = i;
        ff[p->v] = p - g[i].begin();
        if (!z[p->v]) {
          z[p->v] = true;
          q.push(p->v);
        }
      }
    }
    z[i] = false;
  }
  return d[t];
}
pair<int, int> min_cost(int s, int t, int n) {
  int flow = 0;
  pair<int, int> cost = {0, 0};
  while (SPFA(s, t, n) < (pair<int, int>){0, 0}) {
    int i = t, now = INF;
    while (i != s) {
      node &p = g[fa[i]][ff[i]];
      i = fa[i];
      if (p.f < now) now = p.f;
    }
    flow += now;
    i = t;
    while (i != s) {
      g[fa[i]][ff[i]].f -= now;
      cost = {cost.first + now * g[fa[i]][ff[i]].w.first,
              cost.second + now * g[fa[i]][ff[i]].w.second};
      g[i][g[fa[i]][ff[i]].couple].f += now;
      i = fa[i];
    }
  }
  return cost;
}
const int N = 510;
int n, x, y, a[N], q1, q2, r1[N], r2[N], src, tgt, wts = 0;
vector<int> g1[N], g2[N];
void dfs1(int s, int p = 0, int pre = src) {
  if (r1[s]) {
    newnode(pre, n + s, r1[s], {-1, 0});
    newnode(n + s, s, 1, {0, -a[s]});
  } else {
    newnode(pre, s, 1, {0, -a[s]});
  }
  for (int v : g1[s])
    if (v != p) dfs1(v, s, r1[s] ? n + s : pre);
}
void dfs2(int s, int p = 0, int pre = tgt) {
  if (r2[s]) {
    newnode(n + n + s, pre, r2[s], {-1, 0});
    newnode(s, n + n + s, 1, {0, 0});
  } else {
    newnode(s, pre, 1, {0, 0});
  }
  for (int v : g2[s])
    if (v != p) dfs2(v, s, r2[s] ? n + n + s : pre);
}
signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> x >> y;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  for (int _ = 0; _ < (n - 1); _++) {
    int u, v;
    cin >> u >> v;
    g1[u].push_back(v);
    g1[v].push_back(u);
  }
  for (int _ = 0; _ < (n - 1); _++) {
    int u, v;
    cin >> u >> v;
    g2[u].push_back(v);
    g2[v].push_back(u);
  }
  cin >> q1;
  for (int _ = 0; _ < (q1); _++) {
    int k, num;
    cin >> k >> num;
    r1[k] = num;
    wts += num;
  }
  cin >> q2;
  for (int _ = 0; _ < (q2); _++) {
    int k, num;
    cin >> k >> num;
    r2[k] = num;
    wts += num;
  }
  src = n + n + n + 1;
  tgt = n + n + n + 1 + 1;
  dfs1(x);
  dfs2(y);
  pair<int, int> ans = min_cost(src, tgt, tgt);
  cout << (ans.first != -wts ? -1 : -ans.second) << endl;
  return 0;
}
