#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, e, v, u;
int node;
int t;
long long noofways = 1;
int root = 0;
int tot;
stack<int> ss;
int p = 0;
bool visited[110000];
vector<int> g[110000];
vector<int> r[110000];
int count1 = 0;
set<pair<long long, int>> s1;
pair<long long, int> pa;
vector<long long> cost1;
long long price;
long long mincost = 0;
void initialise() {
  for (int i = 0; i < 110000; i++) visited[i] = 0;
}
set<pair<long long, int>>::iterator it, it1;
void noofwayfunc() {
  p = 0;
  it = s1.begin();
  it1 = s1.begin();
  mincost += (*s1.begin()).first;
  t = (*it1).first;
  for (it1 = s1.begin(); it1 != s1.end(); ++it1) {
  }
  for (it1 = s1.begin(); it1 != s1.end(); ++it1) {
    if ((*it1).first == t) {
      p++;
    } else {
      break;
    }
  }
  noofways *= p;
  noofways %= 1000000007;
  s1.clear();
}
void dfs1(int n) {
  pa = make_pair(cost1[n], n);
  s1.insert(pa);
  visited[n] = 1;
  for (int i = 0; i < r[n].size(); i++) {
    if (!visited[r[n][i]]) {
      visited[r[n][i]] = 1;
      pa = make_pair(cost1[r[n][i]], r[n][i]);
      s1.insert(pa);
      dfs1(r[n][i]);
    }
  }
}
void dfs(int n) {
  visited[n] = 1;
  for (int i = 0; i < g[n].size(); i++)
    if (!visited[g[n][i]]) {
      dfs(g[n][i]);
    }
  ss.push(n);
}
void kosaraju() {
  dfs(root);
  for (int i = 0; i < tot; i++)
    if (visited[i] != 1) dfs(i);
  initialise();
  while (!ss.empty()) {
    node = ss.top();
    ss.pop();
    if (visited[node] == 0) {
      dfs1(node);
      noofwayfunc();
    }
  }
  cout << mincost << " " << noofways;
}
int main() {
  cin >> tot;
  for (int i = 0; i < tot; i++) {
    cin >> price;
    cost1.push_back(price);
  }
  cin >> e;
  if (e >= 1) {
    cin >> u >> v;
    root = u - 1;
    g[u - 1].push_back(v - 1);
    r[v - 1].push_back(u - 1);
    for (int i = 1; i < e; i++) {
      cin >> u >> v;
      g[u - 1].push_back(v - 1);
      r[v - 1].push_back(u - 1);
    }
    kosaraju();
  } else {
    kosaraju();
  }
  return 0;
}
