#include <bits/stdc++.h>
using namespace std;
const int maxN = 100007;
const int maxM = 300007;
const long long INF = (1LL << 60);
const long long M = 1000000007;
long long C[maxN];
vector<int> G[maxN];
vector<int> H[maxN];
int V[maxN];
stack<int> S;
vector<int> SSS[maxN];
void DFSG(int x) {
  V[x] = 1;
  for (int g : G[x])
    if (V[g] == 0) DFSG(g);
  S.push(x);
}
void DFSH(int x, int y) {
  V[x] = 2;
  SSS[y].push_back(x);
  for (int h : H[x])
    if (V[h] == 1) DFSH(h, y);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b, k;
  long long ans = 0, cmb = 1, tans, tcmb;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> C[i];
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b;
    G[a].push_back(b);
    H[b].push_back(a);
  }
  for (int i = 1; i <= n; ++i) {
    if (V[i] == 0) DFSG(i);
  }
  k = 0;
  while (!S.empty()) {
    a = S.top();
    S.pop();
    if (V[a] == 1) {
      ++k;
      DFSH(a, k);
    }
  }
  for (int i = 1; i <= k; ++i) {
    tans = INF;
    tcmb = 1;
    for (int s : SSS[i]) {
      if (C[s] < tans) {
        tans = C[s];
        tcmb = 1;
      } else if (C[s] == tans) {
        ++tcmb;
      }
    }
    ans += tans;
    cmb *= tcmb;
    cmb %= M;
  }
  cout << ans << ' ' << cmb << "\n";
  return 0;
}
