#include <bits/stdc++.h>
using std::queue;
using std::vector;
const int inf = 5e8 + 7;
int a[505];
vector<int> g[2][505];
int tag[2][505];
int parent[2][505];
int go[2][505];
int vis[1505];
int left[2][505];
struct Edge {
  int u, v, rev;
  int cap, cost;
  Edge(int u, int v, int rev, int cap, int cost)
      : u(u), v(v), rev(rev), cap(cap), cost(cost) {}
};
vector<Edge> edge[1505];
int dis[1505], depth[1505];
void dfs(int u, int lastTag, int tag[505], vector<int> g[505], int parent[505],
         int go[505]) {
  vis[u] = 1;
  if (tag[u] != 0) lastTag = u;
  go[u] = lastTag;
  for (int v : g[u]) {
    if (!vis[v]) {
      parent[v] = lastTag;
      dfs(v, lastTag, tag, g, parent, go);
    }
  }
  vis[u] = 0;
}
void addEdge(int u, int v, int cap, int cost) {
  int ru = edge[u].size(), rv = edge[v].size();
  edge[u].push_back(Edge(u, v, rv, cap, cost));
  edge[v].push_back(Edge(v, u, ru, 0, -cost));
}
int spfa(int s, int t, int n) {
  for (int i = 1; i <= n; i++) depth[i] = vis[i] = 0, dis[i] = inf;
  queue<int> Q;
  depth[s] = 1, dis[s] = 0;
  vis[s] = 1;
  Q.push(s);
  while (Q.size() != 0) {
    int u = Q.front();
    Q.pop();
    vis[u] = 0;
    for (Edge e : edge[u]) {
      if (dis[e.v] > dis[u] + e.cost && e.cap > 0) {
        depth[e.v] = depth[u] + 1;
        dis[e.v] = dis[u] + e.cost;
        if (!vis[e.v]) {
          vis[e.v] = 1;
          Q.push(e.v);
        }
      }
    }
  }
  return depth[t];
}
int min(int a, int b) { return a > b ? b : a; }
int dfs(int s, int t, int upper, int& cost) {
  if (s == t || upper == 0)
    return upper;
  else {
    int sumFlow = 0;
    for (Edge& e : edge[s]) {
      if (upper == 0) break;
      if (e.cap > 0 && ((dis[s] + e.cost) == dis[e.v]) &&
          ((depth[s] + 1)) == depth[e.v]) {
        int add = dfs(e.v, t, min(upper, e.cap), cost);
        sumFlow += add, edge[e.v][e.rev].cap += add;
        upper -= add, e.cap -= add;
        cost += add * e.cost;
      }
    }
    return sumFlow;
  }
}
void dinic(int s, int t, int n, int& flow, int& cost) {
  flow = 0, cost = 0;
  while (spfa(s, t, n) != 0) {
    int add = -1;
    while (add != 0) {
      add = dfs(s, t, inf, cost);
      flow += add;
    }
  }
}
int judge(int n) {
  int s = 2 * n + 1;
  int ok = 1;
  for (Edge e : edge[s]) {
    if (left[0][e.v] != 0 && e.cap != 0) ok = 0;
  }
  if (!ok) return ok;
  return ok;
}
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int rnd = 0; rnd < 2; rnd++) {
    for (int i = 1; i <= n - 1; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      g[rnd][u].push_back(v);
      g[rnd][v].push_back(u);
    }
  }
  int ok = 1;
  for (int rnd = 0; rnd < 2; rnd++) {
    int q;
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
      int k, x;
      scanf("%d%d", &k, &x);
      if (tag[rnd][k] != 0) {
        if (tag[rnd][k] != x)
          ok = 0;
        else
          tag[rnd][k] = x;
      } else
        tag[rnd][k] = x;
      left[rnd][k] = x;
    }
  }
  if (!ok || tag[0][x] != tag[1][y]) {
    printf("-1\n");
    return 0;
  }
  parent[0][x] = -1;
  dfs(x, -1, tag[0], g[0], parent[0], go[0]);
  parent[1][y] = -1;
  dfs(y, -1, tag[1], g[1], parent[1], go[1]);
  for (int rnd = 0; rnd < 2; rnd++) {
    for (int i = 1; i <= n; i++) {
      int p = parent[rnd][i];
      if (p != -1) left[rnd][p] -= tag[rnd][i];
    }
  }
  int s = 2 * n + 1, t = 2 * n + 2;
  for (int i = 1; i <= n; i++) {
    if (tag[0][i] != 0) {
      if (left[0][i] < 0) ok = 0;
      int fp = i;
      addEdge(s, fp, left[0][i], 0);
    }
    if (tag[1][i] != 0) {
      if (left[1][i] < 0) ok = 0;
      int fp = i + n;
      addEdge(fp, t, left[1][i], 0);
    }
    int u = go[0][i], v = go[1][i] + n;
    addEdge(u, v, 1, -a[i]);
  }
  if (!ok) {
    printf("-1\n");
    return 0;
  }
  int flow = -1, cost = -1;
  dinic(s, t, 2 * n + 2, flow, cost);
  if (flow != tag[0][x])
    printf("-1\n");
  else
    printf("%d\n", -cost);
  return 0;
}
