#include <bits/stdc++.h>
using namespace std;
vector<long long> Edge[100010];
long long ar[100010];
bool Visit[100010 + 7];
bool InStk[100010 + 7];
long long Low[100010 + 7], I;
long long Ind[100010 + 7];
stack<long long> Stk;
long long ans1, ans2;
void SCC(long long u) {
  Visit[u] = true;
  InStk[u] = true;
  Ind[u] = ++I;
  Low[u] = I;
  Stk.push(u);
  for (int i = 0; i < Edge[u].size(); i++) {
    long long v = Edge[u][i];
    if (!Visit[v]) {
      SCC(v);
      Low[u] = min(Low[u], Low[v]);
    } else if (InStk[v]) {
      Low[u] = min(Low[u], Ind[v]);
    }
  }
  if (Low[u] != Ind[u]) return;
  long long mn = LONG_LONG_MAX, num = 0;
  while (Stk.top() != u) {
    long long v = Stk.top();
    if (mn > ar[v]) {
      mn = ar[v];
      num = 1;
    } else if (mn == ar[v]) {
      num++;
    }
    Stk.pop();
    InStk[v] = false;
  }
  long long v = Stk.top();
  if (mn > ar[v]) {
    mn = ar[v];
    num = 1;
  } else if (mn == ar[v]) {
    num++;
  }
  ans2 *= num;
  ans2 %= 1000000007;
  ans1 += mn;
  Stk.pop();
  InStk[u] = false;
}
int main() {
  int n, m;
  while (cin >> n) {
    for (int i = 0; i < 100010; ++i) Edge[i].clear();
    for (int i = 0; i < n; ++i) scanf("%I64d", &ar[i + 1]);
    cin >> m;
    long long u, v;
    for (int i = 0; i < m; ++i) {
      scanf("%I64d %I64d", &u, &v);
      Edge[u].push_back(v);
    }
    memset(Visit, 0, sizeof(Visit));
    memset(InStk, 0, sizeof(InStk));
    memset(Low, 0, sizeof(Low));
    memset(Ind, 0, sizeof(Ind));
    ans1 = 0;
    ans2 = 1;
    for (int i = 1; i <= n; i++) {
      if (Visit[i]) continue;
      SCC(i);
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
