#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> G[N];
map<pair<int, int>, int> edge;
int res[N];
int par[N];
int col[N];
int parent(int u) {
  if (par[u] == u) return u;
  return par[u] = parent(par[u]);
}
int dfs(int u, int p) {
  int sum = col[u];
  for (auto v : G[u]) {
    if (v != p) {
      int x = dfs(v, u);
      sum += x;
      if (edge.find(make_pair(u, v)) != edge.end()) {
        res[edge[make_pair(u, v)]] = x;
      } else {
        res[edge[make_pair(v, u)]] = -x;
      }
    }
  }
  return sum;
}
int main() {
  int n, m;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &col[i]);
    sum += col[i];
  }
  if (sum) {
    printf("Impossible");
    return 0;
  }
  cin >> m;
  for (int i = 1; i <= n; i++) par[i] = i;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    edge[make_pair(u, v)] = i;
    if (parent(u) != parent(v)) {
      G[u].push_back(v);
      G[v].push_back(u);
      par[parent(u)] = parent(v);
    }
  }
  dfs(1, -1);
  printf("Possible\n");
  for (int i = 1; i <= m; i++) {
    printf("%d ", res[i]);
  }
}
