#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b,ll mod=MOD){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % mod;
      x = x * x % mod;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    cin >> res;
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

ll gcd(ll a,ll b){
    return b ? gcd(b,a%b) : a;
}

ll func(){
    int n = in();
    vector<ll> line(n);
    foreach(i,line)i=in();
    ll mins= *min_element(all(line));
    map<ll,ll> candidates;
    candidates[mins] = mins;
    method(add,void,ll v,ll value){
        if(v > mins)return;
        if(candidates.count(v)){
            candidates[v] = gcd(candidates[v],value);
        }else{
            candidates[v] = value;
        }
    };
    
    foreach(i,line){
        for(ll j=1;j*j<=i;++j){
            if(i%j)continue;
            add(j,i);
            add(i/j,i);
        }
    }
    ll res = 0;
    foreach(i,candidates){
        if(i.first==i.second)++res;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << func() << endl;
  return 0;
}

#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <sstream>
#include <utility>

using namespace std;

typedef long long ll;

class Graph {
	unordered_map<int, vector<int> > nodes;
	unordered_map<int, ll> sums;
	vector<pair<int, int> > edges;
	unordered_map<int, int> depths;

	void dfs(int start, unordered_set<int>& visited, vector<int>& sorted){
		if(visited.find(start) != visited.end()) return;
		visited.insert(start);

		const auto it = nodes.find(start);
		if(it != nodes.end())
			for(const int neighbor : it->second)
				dfs(neighbor, visited, sorted);

		sorted.push_back(start);
	}

public:
	void add_edge(int a, int b, bool directed=false){
		if(nodes.find(a) == nodes.end()){
			nodes[a] = vector<int>();
			sums[a] = 0;
		}

		nodes[a].push_back(b);

		if(!directed) add_edge(b, a, true);
		else edges.push_back(make_pair(b,a));
	}

	int get_root()	{
		unordered_set<int> visited;
		vector<int> sorted;

		for(const auto& x : nodes) {
			dfs(x.first, visited, sorted);
		}


		return sorted[0];
	}

	void compute_depths(int current, int current_depth, unordered_set<int>& visited){
		if(visited.find(current) != visited.end()) return;
		visited.insert(current);

		depths[current] = current_depth;
		for(const int neighbor : nodes[current])
			compute_depths(neighbor, current_depth + 1, visited);
	}

	void process_query(int t, int e, int x, int root){
		const int ignore = t == 1 ? edges[e-1].second : edges[e-1].first;
		const int not_ignore = t == 1 ? edges[e-1].first : edges[e-1].second;
		
		if(depths[ignore] < depths[not_ignore]){
			sums[not_ignore] += x;
		}
		else{
			sums[root] += x;
			sums[ignore] -= x;
		}
	}

	void print_sums(int current) {
		for(const auto& x : sums){
			cout << x.first << ": " << x.second << "\n";
		}
	}

	void accum_sums(int current, ll current_sum, unordered_set<int>& visited, vector<pair<int,ll> >& out) {
		if(visited.find(current) != visited.end()) return;
		visited.insert(current);

		auto it = sums.find(current);
		if(it == sums.end()) return;

		out.push_back(make_pair(current, current_sum + it->second));

		for(const int neighbor : nodes[current])
			accum_sums(neighbor, current_sum + it->second, visited, out);
	}
};

int main(){
	string num;
	Graph g;

	getline(cin, num);
	int n = stoi(num);
	for(int i = 0; i < n-1; ++i){
		string in;
		getline(cin, in);
		stringstream ss(in);
		
		int a, b;
		ss >> a >> b;

		g.add_edge(a,b);
	}

	unordered_set<int> visited;
	int root = g.get_root();
	g.compute_depths(root, 0, visited);

	getline(cin, num);
	int q = stoi(num);
	for(int i = 0; i < q; ++i){
		string in;
		getline(cin, in);
		stringstream ss(in);
		
		int t, e, x;
		ss >> t >> e >> x;
		g.process_query(t, e, x, root);
	}

	visited = unordered_set<int>();
	vector<pair<int,ll> > out;
	g.accum_sums(root, 0, visited, out);

	sort(out.begin(), out.end());

	for(int i = 0; i < out.size(); i++) cout << out[i].second << "\n";
}
