#include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
template <typename _T>
_T Fabs(_T x) {
  return x < 0 ? -x : x;
}
template <typename _T>
void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while ('0' <= s && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
int n, m, w[100005], head[100005], tot, idx;
int cnt, ans[100005], belong[100005], S[100005];
int dfn[100005], low[100005], sta[100005], stak;
bool insta[100005];
struct edge {
  int to, nxt;
} e[300005];
void addEdge(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
int add(int x, int y) { return x + y >= mo ? x + y - mo : x + y; }
void tarjan(int u) {
  dfn[u] = low[u] = ++idx;
  sta[++stak] = u;
  insta[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (!dfn[v])
      tarjan(v), low[u] = min(low[u], low[v]);
    else if (insta[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    cnt++;
    int v;
    do {
      v = sta[stak--];
      belong[v] = cnt;
      insta[v] = 0;
    } while (u != v);
  }
}
signed main() {
  read(n);
  memset(ans, 0x7f, sizeof(ans));
  long long num = 1, sum = 0;
  for (int i = 1; i <= n; i++) read(w[i]);
  read(m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    read(u);
    read(v);
    addEdge(u, v);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= n; i++) {
    if (ans[belong[i]] > w[i]) ans[belong[i]] = w[i], S[belong[i]] = 0;
    if (ans[belong[i]] == w[i]) S[belong[i]]++;
  }
  for (int i = 1; i <= cnt; i++) sum += 1ll * ans[i], (num *= S[i]) %= mo;
  printf("%lld %lld", sum, num);
  return 0;
}
