#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N), T(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> T[i];
    }
    ll inf = 4e18;
    ll lo = -inf, hi = inf;
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        if (T[i] == 1) {
            sum += A[i];
            lo += A[i];
            hi += A[i];
        }
        if (T[i] == 2) {
            lo = max(lo, A[i]);
            hi = max(lo, hi);
        }
        if (T[i] == 3) {
            hi = min(hi, A[i]);
            lo = min(lo, hi);
        }
    }

    ll ok_lo = lo - sum;
    ll ok_hi = hi - sum;

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        ll x;
        cin >> x;
        if (x > ok_hi) {
            cout << hi << endl;
        } else if (x < ok_lo) {
            cout << lo << endl;
        } else {
            cout << x + sum << endl;
        }
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}
#include<bits/stdc++.h>
using namespace std;

int n,a[105][105],b[105][105];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		b[i][i]=1;
		for(int j=1;j<=n;j++)
			if(s[j-1]=='1')	
				a[i][j]=b[j][i]=1;
	}
	for(int t=1;t<=n;t++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				b[i][j]=b[i][j]|(b[i][t]&b[t][j]);
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		int cnt=0;
		for(int j=1;j<=n;j++)
			if(b[i][j])	cnt++;
		ans+=1.0/cnt;
	}
	printf("%.10lf",ans);
}







