#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MAXM = 300010;
struct Edge {
  int to, next;
} edge[MAXM];
int head[MAXN], tot;
int Low[MAXN], DFN[MAXN], Stack[MAXN], Belong[MAXN];
int Index, top;
int scc;
bool Instack[MAXN];
int num[MAXN];
void addedge(int u, int v) {
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void Tarjan(int u) {
  int v;
  Low[u] = DFN[u] = ++Index;
  Stack[top++] = u;
  Instack[u] = true;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    v = edge[i].to;
    if (!DFN[v]) {
      Tarjan(v);
      if (Low[u] > Low[v]) Low[u] = Low[v];
    } else if (Instack[v] && Low[u] > DFN[v])
      Low[u] = DFN[v];
  }
  if (Low[u] == DFN[u]) {
    scc++;
    do {
      v = Stack[--top];
      Instack[v] = false;
      Belong[v] = scc;
      num[scc]++;
    } while (v != u);
  }
}
void solve(int N) {
  memset(DFN, 0, sizeof(DFN));
  memset(Instack, false, sizeof(Instack));
  memset(num, 0, sizeof(num));
  Index = scc = top = 0;
  for (int i = 1; i <= N; i++)
    if (!DFN[i]) Tarjan(i);
}
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
}
int a[MAXN];
int Max[MAXN];
int cc[MAXN];
const int MOD = 1e9 + 7;
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    init();
    int m;
    int u, v;
    scanf("%d", &m);
    while (m--) {
      scanf("%d%d", &u, &v);
      addedge(u, v);
    }
    solve(n);
    for (int i = 1; i <= scc; i++) {
      Max[i] = 2000000000;
      cc[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] < Max[Belong[i]]) {
        Max[Belong[i]] = a[i];
        cc[Belong[i]] = 1;
      } else if (a[i] == Max[Belong[i]])
        cc[Belong[i]]++;
    }
    long long ans1 = 0, ans2 = 1;
    for (int i = 1; i <= scc; i++) {
      ans1 += Max[i];
      ans2 = ans2 * cc[i] % (MOD);
    }
    printf("%I64d %I64d\n", ans1, ans2);
  }
  return 0;
}
