#include <bits/stdc++.h>
const long long mod = 1000000007;
using namespace std;
long long w[600001];
long long head[600001], nxt[600001], to[600001], dfn[600001], low[600001],
    sta[600001], vis[600001], col[600001], sum[600001];
long long cnt[600001];
long long anss[600001];
long long n, m;
long long nume;
long long numc;
long long num2;
void add(long long a, long long b) {
  ++nume;
  to[nume] = b;
  nxt[nume] = head[a];
  head[a] = nume;
}
long long deep = 0, top = 0;
void tarjan(long long u) {
  dfn[u] = low[u] = ++deep;
  vis[u] = 1;
  sta[++top] = u;
  for (long long i = head[u]; i; i = nxt[i]) {
    long long v = to[i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (!col[v]) {
      low[u] = min(low[u], low[v]);
    }
  }
  if (dfn[u] == low[u]) {
    col[u] = ++numc;
    cnt[numc] = w[u];
    sum[numc] = 1;
    vis[u] = 0;
    while (sta[top] != u) {
      col[sta[top]] = numc;
      if (w[sta[top]] < cnt[numc]) {
        cnt[numc] = w[sta[top]];
        sum[numc] = 0;
      }
      if (w[sta[top]] == cnt[numc]) ++sum[numc];
      vis[sta[top--]] = 0;
    }
    --top;
  }
  return;
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &w[i]);
  }
  scanf("%lld", &m);
  for (long long i = 1; i <= m; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    add(x, y);
  }
  for (long long i = 1; i <= n; ++i) {
    if (!dfn[i]) tarjan(i);
  }
  long long ans1 = 0, ans2 = 1;
  for (long long i = 1; i <= numc; ++i) {
    ans1 += cnt[i];
    ans2 *= sum[i];
    ans2 %= mod;
  }
  printf("%lld %lld", ans1, ans2);
  return 0;
}
