#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long 
#define rep(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
//#define LOCAL_TEST
#define init_val 2500
template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;}
//----------def struct st----------
struct st
{
	int fif;
	int fis;
	int se;
	bool operator<(const st&st1)const{return se<st1.se;};
	bool operator>(const st&st1)const{return se>st1.se;};
};
//----------global args----------
int si,sj,ti,tj,A;double E;
vector<vector<vector<st>>>G(30,vector<vector<st>>(30));
//----------def input----------
#ifdef LOCAL_TEST
void input()
{
	int h,v;
	rep(i,30)rep(j,29)
	{
		cin>>h;
		G[i][j].push_back(st{i,j+1,init_val});
		G[i][j+1].push_back(st{i,j,init_val});
	}
	rep(i,29)rep(j,30)
	{
		cin>>v;
		G[i][j].push_back(st{i+1,j,init_val});
		G[i+1][j].push_back(st{i,j,init_val});
	}
}
#else
void input()
{
	rep(i,30)rep(j,29){G[i][j].push_back(st{i,j+1,init_val});G[i][j+1].push_back(st{i,j,init_val});}
	rep(i,29)rep(j,30){G[i][j].push_back(st{i+1,j,init_val});G[i+1][j].push_back(st{i,j,init_val});}
}
#endif
//----------def solve----------
#ifdef LOCAL_TEST
void in_a_e(){cin>>A>>E;}
#else
void in_a_e(){cin>>A;}
#endif
void solve()
{
	cin>>si>>sj>>ti>>tj;
	vector<vector<int>>dist(30,vector<int>(30,1LL<<60));dist[si][sj]=0;
	vector<vector<P>>prev(30,vector<P>(30,{-1,-1}));
	priority_queue<st,vector<st>,greater<st>>pq;
	pq.push(st{0,si,sj});
	while(!pq.empty())
	{
		auto[d,v1,v2]=pq.top();
		pq.pop();
		if(d>dist[v1][v2])continue;
		for(auto e:G[v1][v2])if(chmin(dist[e.fif][e.fis],dist[v1][v2]+e.se))
		{
			prev[e.fif][e.fis]={v1,v2};
			pq.push(st{dist[e.fif][e.fis],e.fif,e.fis});
		}
	}
	vector<P>keiro;
	for(P cur={ti,tj};cur!=(P){-1,-1};cur=prev[cur.first][cur.second])keiro.push_back(cur);
	reverse(keiro.begin(),keiro.end());
	int keirosize=keiro.size();
	for(int i=1;i<keirosize;i++)
	{
		if(keiro[i-1].first-keiro[i].first<0)cout<<'D';
		else if(keiro[i-1].first-keiro[i].first>0)cout<<'U';
		if(keiro[i-1].second-keiro[i].second<0)cout<<'R';
		else if(keiro[i-1].second-keiro[i].second>0)cout<<'L';
	}
	cout<<endl;
	in_a_e();
	for(int i=1;i<keirosize;i++)
	{
		for(auto&it:G[keiro[i].first][keiro[i].second])
		{
			if(it.fif==keiro[i+1].first&&it.fis==keiro[i+1].second)
			{
				if(it.se==init_val)it.se=A/keirosize;
				else it.se=(it.se+A/keirosize)/2;
			}
		}
	}
}
//-----------main-----------
main()
{
	input();
	rep(i,1000)solve();
}
#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(const T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
//#define int long long

#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define rep(i,a) for(int i = 0;i<(int)a;i++)
#define All(x) x.begin(),x.end()
#define all(x) x.begin() + 1,x.end()

//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 6,M = 1<<18 + 6;
const int mod = 1e9 + 7;

void solve(){
    int n; cin>>n;
    ll lb = -INF,ub = INF,add = 0;
    For(i,1,n){
        ll a,t;
        cin>>a>>t;
        if(t == 1) {
            lb += a;
            ub += a;
            add += a; 
        }
        else if(t == 2){
            lb = max(lb,a);
            ub = max(ub,a);
        }
        else{
            lb = min(lb,a);
            ub = min(ub,a);
        }
    }
    auto clamp = [&](ll val,ll mi,ll mx)->ll{
        if(val < mi) return mi;
        if(val > mx) return mx;
        return val;
    };
    int q; cin>>q;
    while(q--){
        ll x; cin>>x;
        cout<<clamp(x + add,lb,ub)<<"\n";
    }
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    solve();
    return 0;
}

