#include <bits/stdc++.h>
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct node {
  int y, z, next;
} data[330000];
int dfn[110000], low[110000], num, size[110000], a[110000], h[110000], s,
    b[110000], n, m, min1[110000];
bool stackf[110000];
inline int min(int x, int y) { return x < y ? x : y; }
std::stack<int> q;
void tarjan(int x) {
  dfn[x] = ++num;
  low[x] = num;
  q.push(x);
  stackf[x] = true;
  for (int i = h[x]; i; i = data[i].next) {
    int y = data[i].y;
    if (!dfn[y])
      tarjan(y), low[x] = min(low[x], low[y]);
    else if (stackf[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    int y;
    s++;
    min1[s] = 0x7f7f7f7f;
    do {
      y = q.top();
      b[y] = s;
      q.pop();
      stackf[y] = false;
      if (a[y] < min1[s])
        min1[s] = a[y], size[s] = 1;
      else if (a[y] == min1[s])
        size[s]++;
    } while (y != x);
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    data[i].y = y;
    data[i].next = h[x];
    h[x] = i;
  }
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) tarjan(i);
  long long ans1 = 1, ans = 0;
  for (int i = 1; i <= s; ++i) ans += min1[i], (ans1 *= size[i]) %= 1000000007;
  printf("%lld %lld", ans, ans1);
  return 0;
}
