#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> pii;
typedef vector<long long> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
vi adj1[100001];
vi adj2[100001];
vi vis(1e5 + 1);
vi nodes;
void dfs1(long long v) {
  vis[v] = 1;
  for (auto u : adj1[v]) {
    if (vis[u]) continue;
    dfs1(u);
  }
  nodes.push_back(v);
}
vi vec;
void dfs2(long long v) {
  vis[v] = 1;
  for (auto u : adj2[v]) {
    if (vis[u]) continue;
    dfs2(u);
  }
  vec.push_back(v);
}
const long long mod = 1e9 + 7;
void solve() {
  long long n;
  cin >> n;
  vi v(n + 1);
  for (long long i = (1); i < (n + 1); i += 1) cin >> v[i];
  long long m;
  cin >> m;
  for (long long i = (0); i < (m); i += 1) {
    long long a, b;
    cin >> a >> b;
    adj1[a].push_back(b);
    adj2[b].push_back(a);
  }
  for (long long i = (1); i < (n + 1); i += 1) {
    if (!vis[i]) dfs1(i);
  }
  reverse(nodes.begin(), nodes.end());
  vis.clear();
  vis.resize(1e5 + 1);
  vvi ans;
  for (auto i : nodes) {
    if (!vis[i]) {
      dfs2(i);
      ans.push_back(vec);
      vec.clear();
    }
  }
  vvi cost;
  for (auto vecc : ans) {
    vi v1;
    for (auto i : vecc) {
      v1.push_back(v[i]);
    }
    sort(v1.begin(), v1.end());
    cost.push_back(v1);
  }
  long long min_cost = 0, ways = 1;
  for (auto vecc : cost) {
    long long x = 0;
    min_cost += vecc[0];
    for (auto i : vecc) {
      if (i == vecc[0])
        x++;
      else
        break;
    }
    ways *= x;
    ways %= mod;
  }
  cout << min_cost << " " << ways << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
