#include <bits/stdc++.h>
using namespace std;
void printVector(vector<string> &v) {
  for (auto x : v) cout << x << "\n";
}
void printVector(vector<int> &v) {
  for (auto x : v) cout << x << " ";
  cout << "\n";
}
vector<vector<int> > edges, revedges;
vector<bool> visited;
vector<int> order, component;
void dfs1(int v) {
  visited[v] = true;
  for (int i = 0; i < edges[v].size(); ++i)
    if (!visited[edges[v][i]]) dfs1(edges[v][i]);
  order.push_back(v);
}
void dfs2(int v) {
  visited[v] = true;
  component.push_back(v);
  for (int i = 0; i < revedges[v].size(); i++) {
    if (!visited[revedges[v][i]]) dfs2(revedges[v][i]);
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int t;
  t = 1;
  long long int mod = 1e9 + 7;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> cost(n);
    for (int i = 0; i < n; i++) {
      cin >> cost[i];
    }
    int m;
    cin >> m;
    edges.resize(n);
    revedges.resize(n);
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      edges[u].push_back(v);
      revedges[v].push_back(u);
    }
    visited.assign(n, false);
    for (int i = 0; i < n; i++) {
      if (!visited[i]) {
        dfs1(i);
      }
    }
    visited.assign(n, false);
    long long int ans1 = 0, ans2 = 1;
    long long int mn = 1e9;
    long long int cnt = 0;
    for (int i = 0; i < n; i++) {
      int v = order[n - 1 - i];
      if (!visited[v]) {
        dfs2(v);
        for (auto x : component) {
          if (cost[x] < mn) {
            mn = cost[x];
            cnt = 1;
          } else if (cost[x] == mn) {
            cnt++;
          }
        }
        ans1 += mn;
        ans2 = (ans2 * cnt) % mod;
        component.clear();
        mn = 1e9;
        cnt = 0;
      }
    }
    cout << ans1 << " " << ans2 << "\n";
  }
}
