#include <bits/stdc++.h>
using namespace std;
long long mod = (1000000007LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
void read(vector<long long> &w, long long n) {
  w.resize(n);
  for (long long i = 0; i < n; i++) cin >> w[i];
}
void print(vector<long long> &w) {
  for (long long i = 0; i < (long long)(w).size(); i++) {
    if (i == (long long)(w).size() - 1)
      cout << w[i] << "\n";
    else
      cout << w[i] << " ";
  }
}
long long prodmod(vector<long long> w);
long long summod(vector<long long> w);
long long cap[300050][2], sum[300050][2], n, m, q, k, v[300050], ans, x, y,
    T[300050][2], id[300050][3];
vector<long long> grafo[300050][2];
long long par[300050][2], good[300050][2];
pair<long long, long long> w[300050];
string second;
long long root;
void dfs(long long x, long long p, long long flag, long long &acum) {
  if (T[x][flag] != -1) {
    acum += T[x][flag];
    if (x != root) return;
  }
  for (auto v : grafo[x][flag]) {
    if (v == p) continue;
    dfs(v, x, flag, acum);
  }
}
void dfs0(long long x, long long p, long long flag) {
  par[x][flag] = p;
  for (auto v : grafo[x][flag]) {
    if (v == p) continue;
    dfs0(v, x, flag);
  }
}
void dfs2(long long x, long long p, long long lst, long long flag) {
  if (T[x][flag] != -1) {
    lst = x;
  }
  good[x][flag] = lst;
  for (auto v : grafo[x][flag]) {
    if (v == p) continue;
    dfs2(v, x, lst, flag);
  }
}
namespace mcmf {
struct edge {
  long long dest, cap, re, cost, flow;
};
const long long MAXV = 112345;
const long long infll = 0x3f3f3f3f3f3f3f3fLL;
const long long inf = 0x3f3f3f3f;
long long n, second, t, p[MAXV], e_used[MAXV];
bool in_queue[MAXV];
long long d[MAXV];
vector<vector<edge>> graph;
void init(long long _n, long long _s, long long _t) {
  n = _n, second = _s, t = _t;
  graph = vector<vector<edge>>(n + 1);
}
void put_edge(long long u, long long v, long long cap, long long cost) {
  graph[u].push_back({v, cap, (long long)graph[v].size(), cost, 0});
  graph[v].push_back({u, 0, (long long)graph[u].size() - 1, -cost, 0});
}
bool spfa() {
  memset(in_queue, 0, sizeof(bool) * (n + 1));
  memset(d, 0x3f, sizeof(long long) * (n + 1));
  queue<long long> q;
  d[second] = 0;
  p[second] = second;
  q.push(second);
  while (!q.empty()) {
    long long a = q.front();
    q.pop();
    in_queue[a] = false;
    for (long long i = 0; i < graph[a].size(); i++) {
      edge &e = graph[a][i];
      if (e.cap - e.flow > 0 && d[e.dest] > d[a] + e.cost) {
        d[e.dest] = d[a] + e.cost;
        p[e.dest] = a;
        e_used[e.dest] = i;
        if (!in_queue[e.dest]) q.push(e.dest);
        in_queue[e.dest] = true;
      }
    }
  }
  return d[t] < infll;
}
pair<long long, long long> mincost_maxflow() {
  pair<long long, long long> retv = pair<long long, long long>(0, 0);
  while (spfa()) {
    long long x = inf;
    for (long long i = t; p[i] != i; i = p[i])
      x = min(x, graph[p[i]][e_used[i]].cap - graph[p[i]][e_used[i]].flow);
    for (long long i = t; p[i] != i; i = p[i])
      graph[p[i]][e_used[i]].flow += x,
          graph[i][graph[p[i]][e_used[i]].re].flow -= x;
    retv.first += x;
    retv.second += x * d[t];
  }
  return retv;
}
}  // namespace mcmf
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x >> y;
  long long qaa[2] = {-1, -1};
  for (long long i = 1; i <= n; i++) cin >> v[i];
  for (long long i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    grafo[a][0].push_back(b);
    grafo[b][0].push_back(a);
  }
  for (long long i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    grafo[a][1].push_back(b);
    grafo[b][1].push_back(a);
  }
  long long cnt = 0;
  for (long long group = 0; group < 2; group++) {
    for (long long i = 1; i <= n; i++) {
      cnt++;
      id[i][group] = cnt;
    }
  }
  long long src = 0, snk = cnt + 1;
  mcmf::init(cnt + 1, src, snk);
  dfs0(x, x, 0), dfs0(y, y, 1);
  memset(T, -1, sizeof T);
  long long MX = (long long)(1e6);
  bool can = 1;
  for (long long u = 0; u < 2; u++) {
    long long q;
    cin >> q;
    while (q--) {
      long long k, h;
      cin >> k >> h;
      T[k][u] = h;
      if (u == 0 and k == x) qaa[0] = h;
      if (u == 1 and k == y) qaa[1] = h;
    }
    if (!u)
      dfs2(x, x, x, u);
    else
      dfs2(y, y, y, u);
    for (long long i = 1; i <= n; i++) {
      if (T[i][u] == -1) continue;
      long long acum = 0;
      root = i;
      dfs(i, par[i][u], u, acum);
      cap[i][u] = 2 * T[i][u] - acum;
      if (cap[i][u] < 0) {
        can = 0;
        continue;
      }
      if (!u) {
        mcmf::put_edge(src, id[i][u], cap[i][u], 0);
      } else {
        mcmf::put_edge(id[i][u], snk, cap[i][u], 0);
      }
    }
  }
  if (!can) cout << "-1\n", exit(0);
  for (long long i = 1; i <= n; i++) {
    long long j = id[i][2];
    long long L = good[i][0], R = good[i][1];
    mcmf::put_edge(id[L][0], id[R][1], 1, -v[i]);
  }
  if (qaa[0] != qaa[1]) {
    cout << "-1\n";
    return 0;
  }
  auto ans = mcmf::mincost_maxflow();
  if (ans.first == qaa[0])
    cout << -ans.second << "\n";
  else
    cout << "-1\n";
}
long long summod(vector<long long> w) {
  long long curr = 0;
  for (long long i = 0; i < (long long)(w).size(); i++) {
    curr = (curr + w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
long long prodmod(vector<long long> w) {
  long long curr = 1;
  for (long long i = 0; i < (long long)(w).size(); i++) {
    if (w[i] >= mod) w[i] %= mod;
    curr = (curr * w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
