#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const double EPS = 1e-13;
int n, m, ile = 0;
stack<int> s;
vector<int> bylo, pusty, odp, bylo2;
vector<vector<int> > v, rv, scc(1, pusty), w;
void dfstopo(int a) {
  bylo[a] = 1;
  for (int i = 0; i < v[a].size(); i++)
    if (!bylo[v[a][i]]) dfstopo(v[a][i]);
  s.push(a);
}
void revdfs(int a) {
  bylo[a] = ile;
  scc[ile].push_back(a);
  for (int i = 0; i < rv[a].size(); i++)
    if (!bylo[rv[a][i]]) revdfs(rv[a][i]);
}
void znajdzscc() {
  bylo.resize(n, 0);
  for (int i = 0; i < n; i++)
    if (!bylo[i]) dfstopo(i);
  for (int i = 0; i < n; i++) bylo[i] = 0;
  while (s.size()) {
    int a = s.top();
    s.pop();
    if (bylo[a]) continue;
    ile++;
    scc.push_back(pusty);
    revdfs(a);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  vector<int> cost(n);
  for (int i = 0; i < n; i++) cin >> cost[i];
  v.resize(n);
  rv.resize(n);
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    rv[b].push_back(a);
  }
  znajdzscc();
  long long ans = 1, mod = 1000000007, price = 0;
  for (int i = 1; i < scc.size(); i++) {
    long long mini = cost[scc[i][0]], ile22 = 0;
    for (int j = 0; j < scc[i].size(); j++) {
      if (cost[scc[i][j]] < mini) {
        mini = cost[scc[i][j]];
        ile22 = 1;
      } else if (cost[scc[i][j]] == mini)
        ile22++;
    }
    ans = (ans * ile22) % mod;
    price += mini;
  }
  cout << price << " " << ans << "\n";
}
