//solution by Wsl_F
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <cassert>
#include <time.h>
#include <ctime>
#include <memory.h>
#include <complex>
#include <utility>
#include <climits>
#include <cctype>
#include <x86intrin.h>

using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")

typedef long long LL;
typedef unsigned long long uLL;
typedef double dbl;
typedef vector<int> vi;
typedef vector<LL> vL;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;

#define mp(x,y)  make_pair((x),(y))
#define pb(x)  push_back(x)
#define sqr(x) ((x)*(x))

vi v[30];
int t[30];
int indV[30];

int main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 srand(__rdtsc());
 // LL a[110];
 // memset(a,0,sizeof(a));

 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
 //cout<<fixed;
 //cout<<setprecision(9);

 int n,k,p;
 char c;
 string s;
 cin>>k;
 cin>>s;
 cin>>n;

 for (int i= 0; i<n; i++)
 {
    cin>>p>>c;
    v[c-'a'].pb(p);
 }

 for (int i= 0; i<= 'z'-'a'; i++)
 {
    sort(v[i].begin(),v[i].end());
    v[i].pb(-1);
    v[i].pb(-1);
    v[i].pb(-1);
 }

 int l= s.length();
 int L= l*k;

 int j;
 for (int i= 0; i<L; i++)
 {
    j= s[i%l]-'a';
    if (t[j]+1==v[j][indV[j]]) indV[j]++;
    else {t[j]++; cout<<char('a'+j);}
 }
 cout<<endl;
 return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

long k, n;
string s;
vector <long> M[256];
vector <long> D;

void del(long p, char c) {
	size_t c_pos = M[c][p-1];
	M[c].erase( M[c].begin() + (p-1) );
	D[c_pos] = false;
}

int main () {
	for (int i = 0; i < 256; ++i) {
		M[i] = vector <long> ();
	}

	cin >> k;
	cin >> s;
	cin >> n;

	for (long i_k = 0; i_k < k; ++i_k) {
		for (size_t i_s = 0; i_s < s.size(); ++i_s) {
			D.push_back(true);
		    char c = s[i_s];
		    M[c].push_back( i_k * s.size() + i_s );
		}
	}

	int n_com = n;
	while (n_com-- > 0) {
		long p;
		char c ;
		cin >> p >> c;
		del(p, c);
	}

	size_t Ssz = k*s.size() + 1 - n;
	char S[Ssz];

	size_t S_pos = 0;
	for (int i_k = 0; i_k < k; ++i_k) {
		for (size_t i_s = 0; i_s < s.size(); ++i_s) {
			size_t pos = i_k * s.size() + i_s;
			if (D[pos]) {
				S[ S_pos++ ] = s[i_s];
			}
		}
	}
	S[ S_pos ] = '\0';
	cout << S << endl;

	return 0;
}


#define VERBOSE

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int k, n;
string s;
vector <long> M[256];
vector <long> D;

void del(long p, char c) {
	size_t c_pos = M[c][p-1];
	M[c].erase( M[c].begin() + (p-1) );
	D[c_pos] = false;
}

int main () {
	for (int i = 0; i < 256; ++i) {
		M[i] = vector <long> ();
	}

	cin >> k;
	cin >> s;
	cin >> n;

	for (int i_k = 0; i_k < k; ++i_k) {
		for (size_t i_s = 0; i_s < s.size(); ++i_s) {
			D.push_back(true);
		    char c = s[i_s];
		    M[c].push_back( i_k * k + i_s );
		}
	}

	int n_com = n;
	while (n_com--) {
		long p;
		char c ;
		cin >> p >> c;
		del(p, c);
	}

	#ifdef VERBOSE
	cout << "Command: OK" << endl;
	#endif

	size_t Ssz = k*s.size() + 1 - n;
	char S[Ssz];

	size_t S_pos = 0;
	for (int i_k = 0; i_k < k; ++i_k) {
		for (size_t i_s = 0; i_s < s.size(); ++i_s) {
			size_t pos = i_k * k + i_s;
			if (D[pos]) {
				S[ S_pos++ ] = s[i_s];
			}
		}
	}
	S[ S_pos ] = '\0';
	printf("%s\n", S);

	return 0;
}


//#define VERBOSE

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int k, n;
string s;
vector <long> M[256];
vector <long> D;

void del(long p, char c) {
    size_t c_pos = M[c][p-1];
    M[c].erase( M[c].begin() + (p-1) );
    D[c_pos] = false;
}

int main () {
    for (int i = 0; i < 256; ++i) {
        M[i] = vector <long> ();
    }

    cin >> k;
    cin >> s;
    cin >> n;

    for (int i_k = 0; i_k < k; ++i_k) {
        for (size_t i_s = 0; i_s < s.size(); ++i_s) {
            D.push_back(true);
            char c = s[i_s];
            M[c].push_back( i_k * k + i_s );
        }
    }

    int n_com = n;
    while (n_com--) {
        long p;
        char c ;
        cin >> p >> c;
        del(p, c);
    }

    #ifdef VERBOSE
    cout << "Command: OK" << endl;
    #endif

    size_t Ssz = k*s.size() + 1 - n;
    char S[Ssz];

    size_t S_pos = 0;
    for (int i_k = 0; i_k < k; ++i_k) {
        for (size_t i_s = 0; i_s < s.size(); ++i_s) {
            size_t pos = i_k * k + i_s;
            if (D[pos]) {
                S[ S_pos++ ] = s[i_s];
            }
        }
    }
    S[ S_pos ] = '\0';
    printf("%s\n", S);

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#define SIZE 200005

using namespace std;

struct BIT
{
	int bit[SIZE];
	int n;

	void add(int k,int x)
	{
		while(k<=n)
		{
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k)
	{
		int ret=0;
		while(k>0)
		{
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
};
BIT bit[26];
char str[2005];
bool ok[SIZE];

int main()
{
	int k;
	scanf("%d",&k);
	scanf("%s",&str);
	int sz=strlen(str);
	for(int i=0;i<26;i++)
	{
		bit[i].n=sz*k+2;
	}
	for(int i=0;i<sz;i++)
	{
		for(int j=0;j<k;j++)
		{
			bit[str[i]-'a'].add(i+j*sz+1,1);
			ok[i+j*sz]=true;
		}
	}
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++)
	{
		int a;
		char c;
		scanf("%d %c",&a,&c);
		int v=c-'a';
		int s=-1,e=sz*k+2;
		while(e-s>1)
		{
			int med=(s+e)/2;
			if(bit[v].sum(med+1)<a) s=med;
			else e=med;
		}
		bit[v].add(e+1,-1);
		ok[e]=false;
	}
	for(int i=0;i<sz*k;i++)
	{
		if(ok[i])
		{
			printf("%c",str[i%sz]);
		}
	}
	puts("");
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;

int k, n, p, i, j; char c;
string s, s1;
vector < vector <int> > v( 26 );
bool b[200005];

int main()
{
    cin >> k >> s1 >> n;
    for ( i = 0; i < k; i++ ) s += s1;
    for ( i = 0; i < s.size(); i++ )
        v[s[i] - 'a'].push_back( i );
    for ( i = 0; i < n; i++ )
    {
        cin >> p >> c;
        b[v[c - 'a'][p - 1]] = true;
        v[c - 'a'].erase( v[c - 'a'].begin() + p - 1 );
    }
    s1 = "";
    for ( i = 0; i < s.size(); i++ )
        if ( !b[i] ) s1 += s[i];
    cout << s1 << endl;
    //system( "pause" );
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

typedef long long int LL;
typedef pair<int,int> PII;

// Fenwick Tree
class BinaryIndexedTree {
  public:
    //BinaryIndexedTree() : size_(0) {}

    BinaryIndexedTree(int size) {
        size_ = size;
        data_ = vector<int>(size_, 0);
    }

    int size() const { return size_; }

    // v[at] += by
    void update(int at, int by) {
        while (at < size_) {
            data_[at] += by;
            at |= (at + 1);
        }
    }

    // v[0] + v[1] + ... + v[at]
    int query(int at) const {
        int r = 0;
        while (at >= 0) {
            r += data_[at];
            at = (at & (at + 1)) - 1;
        }
        return r;
    }

    // range query [left, right]
    int query(int left, int right) {
        int l = 0;
        if (left > 0)
            l = query(left-1);
        return query(right) - l;
    }

  private:
    int size_;
    vector<int> data_;
};

// Binary search, returns the left-most element in case of repetitions.
int binary_search_left(int key, const BinaryIndexedTree& fenwick) {
    int lo = 0;
    int hi = fenwick.size()-1;

    int lo_ori = lo; // the original lower and upper points
    int hi_ori = hi;

    int mid = 0;
    while (lo <= hi) {
        mid = lo + (hi-lo) / 2;
        int v = fenwick.query(mid);
        if (key <= v) // difference with standar binary search
            hi = mid-1;
        else if (key > v)
            lo = mid+1;
        // here we don't have a key == fenwick[mid]
        // instead, at the end we look at fenwick[mid] and fenwick[mid+1]
    }

    if (mid >= lo_ori && mid <= hi_ori && fenwick.query(mid) == key)
        return mid;
    if (mid+1 >= lo_ori && mid+1 <= hi_ori && fenwick.query(mid+1) == key)
        return mid+1;
    return -1;
}

int main(int argc, char*argv[]) {
    ios_base::sync_with_stdio(false);
    int k, n, size, p;
    string s, c;
    cin >> k >> s >> n;
    size = s.size();

    // count each character
    vector<int> cnt(26);
    for (int i = 0; i < size; ++i)
        cnt[s[i]-'a']++;

    vector<vector<bool> > valid(26);

    // fenwick tree for each char
    vector<BinaryIndexedTree> fens;
    for (int i = 0; i < 26; ++i) {
        int t = cnt[i] * k;
        fens.push_back(BinaryIndexedTree(t));
        for (int j = 0; j < t; ++j)
            fens[i].update(j, 1);
        valid[i] = vector<bool>(t, true);
    }

    // remove invalid chars from the fenwick tree
    for (int i = 0; i < n; ++i) {
        cin >> p >> c;
        int pos = binary_search_left(p, fens[c[0]-'a']);
        valid[c[0]-'a'][pos] = false;
        fens[c[0]-'a'].update(pos, -1);
    }

    // print valid chars
    cnt = vector<int>(26, 0);
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < size; ++j) {
            int cur = s[j]-'a';
            if (valid[cur][cnt[cur]])
                cout << s[j];
            cnt[cur]++;
        }
    }
    cout << endl;

    return EXIT_SUCCESS;
}


#include <string>
#include <iostream>
#include <vector>
using namespace std;

long k, n;
string s;
vector <long> CS[256];
vector <long> D;

void remove(long, char);

int main () {
	for (int i = 0; i < 256; ++i) {
		CS[i] = vector <long> ();
	}

	cin >> k;
	cin >> s;
	cin >> n;

	for (long i_k = 0; i_k < k; ++i_k) {
		for (size_t i_s = 0; i_s < s.size(); ++i_s) {
			D.push_back(true);
		    char c = s[i_s];
		    CS[c].push_back( i_k * s.size() + i_s );
		}
	}

	int n_com = n;
	while (n_com-- > 0) {
		long p;
		char c ;
		cin >> p >> c;
		remove(p, c);
	}

	size_t Ssz = k*s.size() + 1 - n;
	char S[Ssz];

	size_t S_pos = 0;
	for (int i_k = 0; i_k < k; ++i_k) {
		for (size_t i_s = 0; i_s < s.size(); ++i_s) {
			size_t pos = i_k * s.size() + i_s;
			if (D[pos]) {
				S[ S_pos++ ] = s[i_s];
			}
		}
	}
	S[ S_pos ] = '\0';
	cout << S << endl;

	return 0;
}

void remove(long p, char c) {
	size_t c_pos = CS[c][p-1];
	CS[c].erase( CS[c].begin() + (p-1) );
	D[c_pos] = false;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef double real;
typedef long long int64;
typedef unsigned long long uint64;

const int inf = 0x3f3f3f3f;
const int64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const real eps = 1e-8;

#define maxn 200002
char res[maxn];

int main() {
	int i, j, _;
	int k; scanf("%d", &k);
	gets(res); gets(res);
	int l = strlen(res);
	for(i = 1; i < k; i++)
		for(j = 0; j < l; j++)
			res[i * l + j] = res[j];

	int n; scanf("%d", &n);
	for(_ = 0; _ < n; _++) {
		char let; int num; scanf("%d %c", &num, &let);
		for(i = 0; ; i++) {
			if(res[i] == let) {
				num--;
				if(!num) {
					res[i] = 0;
					break;
				}
			}
		}
	}
	for(i = 0; i < maxn; i++) if(res[i]) putchar(res[i]);
	puts("");

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>

#include <string>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;

#ifdef ILIKEGENTOO
#define Eo(x) { cerr << #x << " = " << (x) << endl; }
#define E(x) { cerr << #x << " = " << (x) << "   "; }
#else
#define Eo(x)
#define E(x)
#endif
#if defined ILIKEGENTOO || !(defined __GNUC__ ) || (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
template<typename T, size_t N> struct array { T val[N]; T& operator[](size_t n) { if(n >= N) assert(false); return val[n]; } T* begin() { return &val[0]; } T* end() { return &val[0]+N; } };
#else
#include <array>
#endif
#define EO(x) Eo(x)
#define Sz(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()

template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }

typedef double real;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pip;

const int inf = 0x3f3f3f3f;
const int64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const real eps = 1e-8;

const int maxn = 2*100001;
char res[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	int k; cin >> k;
	string s; cin >> s;
	vector<int> pos[256];
	for(int i = 0; i < Sz(s); i++) {
		for(int j = 0; j < k; j++)
			pos[const_cast<const string&>(s)[i]].push_back(i + j * Sz(s));
	}
	for(int i = 0; i < 256; i++) sort(All(pos[i]));

	int n; cin >> n;
	for(int _ = 0; _ < n; _++) {
		int num; cin >> num;
		char let; cin >> let;
		for(int i = 0; ; i++) {
			if(pos[let][i]!=-1) {
				num--;
				if(!num) {
					pos[let][i] = -1;
					break;
				}
			}
		}
	}
	for(int i = 'a' ; i <= 'z'; i++) for(int j = 0; j < Sz(pos[i]); j++) if(pos[i][j]!=-1) res[pos[i][j]] = i;
	for(int i = 0; i < maxn; i++) if(res[i]) cout << res[i];
	cout << endl;

	return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; ++i)
#define For(i, st, en) for(int i = (int)st; i <= (int)en; ++i)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

/**
 * The code starts here.
 */

class Fenwick
{
    vector<int> t;
    int n;
public:
    Fenwick(){}
    Fenwick(int n)
    {
        this->n = n;
        t.assign(n, 0);
    }
    Fenwick(const vector<int> & a)
    {
        this->n = a.size();
        t.assign(n, 0);
        for (size_t i = 0; i < a.size(); ++i)
        {
            inc(i, a[i]);
        }
    }
    inline void inc(int i, int delta)
    {
        for (; i < n; i = i | (i + 1))
        {
            t[i] += delta;
        }
    }
    inline int sum(int r) const
    {
        int res = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            res += t[r];
        return res;
    }

    inline int sum(int l, int r) const
    {
        return sum(r) - sum(l - 1);
    }
};

int main()
{
    ios_base::sync_with_stdio(false);

    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.length();
    int len = n * k;

    vector<int> a[26];
    for (int i = 0; i < 26; ++i)
        a[i].assign(len, 0);

    for (int i = 0; i < len; ++i)
    {
        int c = s[i % n] - 'a';
        a[c][i] = 1;
    }

    Fenwick f[26];
    for (int i = 0; i < 26; ++i)
        f[i] = Fenwick(a[i]);

    int m;
    cin >> m;

    for (int i = 0; i < m; ++i)
    {
        int k;
        char c;
        cin >> k >> c;
        //cerr << c << endl;
        int cc = c - 'a';

        int l = 0, r = len - 1;
        while (l < r)
        {
            int m = (l + r) >> 1;
            int d = f[cc].sum(m);
            if (d < k)
            {
                l = m + 1;
            } else
            {
                r = m;
            }
        }
        f[cc].inc(l, -1);
    }

    for (int i = 0; i < len; ++i)
    {
        for (int j = 0; j < 26; ++j)
        {
            if (f[j].sum(i, i))
            {
                putchar('a' + j);
                break;
            }
        }
    }
    putchar('\n');
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
    int n,m,size,used[200005]={0};
    vector <int> d[30];
main()
{
    int len=0,x;
    char ch;
    scanf("%d",&n);
    string str,example;
    cin>>str;
    example="";
    size=str.size();
    for (int i=1;i<=n;i++)
    {
        example+=str;
        for (int q=0;q<size;q++)
        {
            d[str[q]-97].push_back(q+len);
        }
        len+=size;
    }
    scanf("%d",&m);
    for (int i=1;i<=m;i++)
    {
        cin>>x>>ch;
        used[d[ch-97][x-1]]=1;
        d[ch-97].erase(d[ch-97].begin()+(x-1));
    }
    for (int i=0;i<=len;i++)
    {
        if (used[i]==0)
        {
            cout<<char(example[i]);
        }
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
    int n,m,size,used[200005]={0};
    vector <int> d[30];
main()
{
    int len=0,x;
    char ch;
    scanf("%d",&n);
    string str,example;
    cin>>str;
    example="";
    size=str.size();
    for (int i=1;i<=n;i++)
    {
        example+=str;
        for (int q=0;q<size;q++)
        {
            d[str[q]-97].push_back(q+len);
        }
        len+=size;
    }
    scanf("%d",&m);
    for (int i=1;i<=m;i++)
    {
        cin>>x>>ch;
        used[d[ch-97][x-1]]=1;
        d[ch-97].erase(d[ch-97].begin()+(x-1));
    }
    for (int i=0;i<len;i++)
    {
        if (used[i]==0)
        {
            cout<<char(example[i]);
        }
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cctype>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <list>
using namespace std;

#pragma region defines

typedef long long ll;
typedef unsigned long long ull;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
#define REP(to, counter) for (int counter=0; counter < int(to); counter++)
#define X first
#define Y second
#define eps 1E-7
inline vi ReadVI(int count) {vi arrayname(count); REP(count, i) cin >> arrayname[i]; return arrayname; };
#pragma endregion defines
const int MOD = 1000000007;

vvi a(26);
string res;
int main(void)
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	double beginTime=clock();
#endif

	int rep; cin >> rep;
	string s; cin >> s;
	int len = s.length();
	for (int i=0;i<s.size();i++) a[s[i]-97].push_back(i+1);
	for(int k=0;k<26;k++)
		if (a[k].size())
		{
			for(int i=1;i<rep;i++)
			{
				int size = a[k].size();
				for (int j=0;j<size;j++)
					a[k].push_back(a[k][j] + len*i);
			}
		}

	int n; cin >> n;
	for(int i=0;i<n;i++)
	{
		int m; char c;
		scanf("%d %c", &m, &c);
		c -= 97; m--;
		a[c].erase(a[c].begin() + m);
	}
	int m = -1;
	for(int k=0;k<26;k++)
	{
		if (a[k].size())
		{
			auto t = max_element(a[k].begin(), a[k].end());
			m = max(m, *t);
		}
	}

	res = string(m+1, 0);

	for(int k=0;k<26;k++)
	{
		if (a[k].size())
		{
			int size = a[k].size();
			for (int j=0;j<size;j++)
			{
				res[a[k][j]] = char(k+97);
			}
		}
	}

	for(int i=0;i<m+1;i++)
		if (res[i])
			cout << res[i];

#ifndef ONLINE_JUDGE
	double endTime=clock();
	printf("\n***Elapsed = %.5lf******", (endTime-beginTime)/CLOCKS_PER_SEC);
#endif
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cctype>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <list>
using namespace std;

#pragma region defines

typedef long long ll;
typedef unsigned long long ull;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
#define REP(to, counter) for (int counter=0; counter < int(to); counter++)
#define X first
#define Y second
#define eps 1E-7
inline vi ReadVI(int count) {vi arrayname(count); REP(count, i) cin >> arrayname[i]; return arrayname; };
#pragma endregion defines
const int MOD = 1000000007;

vi a[26];

int main(void)
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	double beginTime=clock();
#endif
	int rep; cin >> rep;
	string s; cin >> s;
	int len = s.length();
	for (int i=0;i<s.size();i++) a[s[i]-97].push_back(i+1);
	for(int k=0;k<26;k++)
		if (a[k].size())
		{
			int size = a[k].size();
			for(int i=1;i<rep;i++)
			{
				for (int j=0;j<size;j++)
					a[k].push_back(a[k][j] + len*i);
			}
		}

	int n; cin >> n;
	for(int i=0;i<n;i++)
	{
		int m; char c;
		scanf("%d %c", &m, &c);
		c -= 97; m--;
		auto beg = a[c].begin();
		a[c].erase(beg + m);
	}
	int m = -1;
	for(int k=0;k<26;k++)
	{
		if (a[k].size())
		{
			auto t = max_element(a[k].begin(), a[k].end());
			m = max(m, *t);
		}
	}

	char* res = new char[m+1];
	for(int i=0;i<m+1;i++) res[i] = 0;

	for(int k=0;k<26;k++)
	{
		if (a[k].size())
		{
			int size = a[k].size();
			for (int j=0;j<size;j++)
			{
				res[a[k][j]] = char(k+97);
			}
		}
	}

	for(int i=0;i<m+1;i++)
		if (res[i])
			cout << res[i];

	delete[] res;

#ifndef ONLINE_JUDGE
	double endTime=clock();
	printf("\n***Elapsed = %.5lf******", (endTime-beginTime)/CLOCKS_PER_SEC);
#endif
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cctype>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <list>
using namespace std;

#pragma region defines

typedef long long ll;
typedef unsigned long long ull;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
#define REP(to, counter) for (int counter=0; counter < int(to); counter++)
#define X first
#define Y second
#define eps 1E-7
inline vi ReadVI(int count) {vi arrayname(count); REP(count, i) cin >> arrayname[i]; return arrayname; };
#pragma endregion defines
const int MOD = 1000000007;

vi a[26];

int main(void)
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	double beginTime=clock();
#endif
	int rep; cin >> rep;
	string s; cin >> s;
	int len = s.length();
	for (int i=0;i<s.size();i++) a[s[i]-97].push_back(i+1);
	for(int k=0;k<26;k++)
		if (a[k].size())
		{
			for(int i=1;i<rep;i++)
			{
				int size = a[k].size();
				for (int j=0;j<size;j++)
					a[k].push_back(a[k][j] + len*i);
			}
		}

	int n; cin >> n;
	for(int i=0;i<n;i++)
	{
		int m; char c;
		scanf("%d %c", &m, &c);
		c -= 97; m--;
		a[c].erase(a[c].begin() + m);
	}
	int m = -1;
	for(int k=0;k<26;k++)
	{
		if (a[k].size())
		{
			auto t = max_element(a[k].begin(), a[k].end());
			m = max(m, *t);
		}
	}

	char* res = new char[m+1];
	for(int i=0;i<m+1;i++) res[i] = 0;

	for(int k=0;k<26;k++)
	{
		if (a[k].size())
		{
			int size = a[k].size();
			for (int j=0;j<size;j++)
			{
				res[a[k][j]] = char(k+97);
			}
		}
	}

	for(int i=0;i<m+1;i++)
		if (res[i])
			cout << res[i];

#ifndef ONLINE_JUDGE
	double endTime=clock();
	printf("\n***Elapsed = %.5lf******", (endTime-beginTime)/CLOCKS_PER_SEC);
#endif
}


#include <bits/stdc++.h>
using namespace std;
#define ll 		long long
#define mp 		make_pair
#define sz(v) 	(int)v.size()
#define pb    	push_back
int main(){
	int k,n;
	string s,S;
	cin>>k>>s>>n;
	S=s;
	k--;
	while(k--)
		s+=S;
	vector <int> v[26];
	bool ar[200009];
	memset(ar,1,sizeof(ar));

	for(int i=0;i<sz(s);i++)
		v[s[i]-'a'].pb(i);

	while(n--){
		int x;
		char c;
		cin>>x>>c;
		int num= v[c-'a'][x-1];
		v[c-'a'].erase(v[c-'a'].begin()+x-1);
		ar[num]=0;
	}

	S="";
	for(int i=0;i<sz(s);i++)
		if(ar[i])
			S+=s[i];
	cout<<S<<endl;
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define rep(x, a, b) for(int (x) = (a); (x) < int(b); ++(x))
#define Wait cin.sync(); cin.get();
#define INF_INT 2000000000;
#define INF 0x3F3F3F3F
#define y1 qwerty
#define EPS 1e-6
using namespace std;
typedef long long                  ll;
typedef pair<long long, long long> pll;
typedef pair<int, int>             pii;
typedef pair<double, int>          pdi;
typedef pair<string, string>       pss;

struct node{
	int in[28];
	node(){ rep(i, 0, 26) in[i] = 0; }
}T[4* 2001];

string t[2001], s;
int k, n, p;
char c;
int len;

void build(int v, int tl, int tr){
	if (tl == tr){
		rep(i, 0, len){
			T[v].in[s[i] - 'a']++;
		}
	}
	else{
		int tm = (tl + tr) / 2;
		build(2 * v, tl, tm);
		build(2 * v + 1, tm + 1, tr);
		rep(i, 0, 26) T[v].in[i] = T[2 * v].in[i] + T[2 * v + 1].in[i];
	}
}

void go(int v, int tl, int tr, int num, char ch){
	if (tl == tr){
		int len = t[tl].size(), cnt = 0, i;
		for (i = 0; cnt != num; ++i){
			if (t[tl][i] == ch) ++cnt;
		}
		t[tl].erase(i-1, 1);
		T[v].in[ch - 'a']--;
	}
	else{
		int tm = (tl + tr) / 2;
		if (T[2 * v].in[ch - 'a'] >= num) go(2 * v, tl, tm, num, ch);
		else go(2 * v + 1, tm + 1, tr, num - T[2 * v].in[ch - 'a'], ch);
		rep(i, 0, 26) T[v].in[i] = T[2 * v].in[i] + T[2 * v + 1].in[i];
	}
}

int main(){
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> k;
	cin >> s;
	len = s.length();
	rep(i, 0, k) t[i] = s;
	build(1, 0, k - 1);
	cin >> n;
	rep(i, 0, n){
		cin >> p >> c;
		go(1, 0, k - 1, p, c);
	}
	rep(i, 0, k) cout << t[i];

	//printf("TIME: %.3lf\n", (long double)(clock()) / CLOCKS_PER_SEC);
	Wait
	return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <deque>

using namespace std;

typedef int IntType;
typedef deque<IntType> IntVector;
typedef IntVector::iterator IntIterator;

IntIterator findLowest( IntIterator begin, IntIterator end ) {
    IntIterator iter, min = begin;

    for( iter = begin; iter != end; ++iter ) {
        if( (*iter) < (*min) )
            min = iter;
    }
    return min;
}

int main( int, char** ) {
    int k, n;
    string s;

    cin >> k >> s >> n;

    IntVector operations[30];

    for( int i=0; i < n; ++i ) {
        IntType p;
        char t;

        cin >> p >> t;

        operations[t-'a'].push_back(p);
    }

    // sort
    for( int i=0; i < 30; ++i ) {
        IntVector &Operations = operations[i];

        IntIterator SortedTo = Operations.begin();

        IntVector Sorted;
        while( !Operations.empty() ) {

            IntIterator least = findLowest(Operations.begin(), Operations.end() );
            IntType Value = *least;

            for( IntIterator iter=SortedTo; iter != least; ++iter ) {
                (*iter)--;
            }

            Operations.erase(least);
            Sorted.push_back(Value);
        }
        Operations = Sorted;
    }

    long long count[30];

    for( int i=0; i < 30; ++i ) {
        count[i] = 0;
    }

    long long length = k*s.size();
    for( long long i=0; i < length; ) {
        for( int a=0; a < s.size(); ++a ) {
            char t = s[a];

            if( operations[t-'a'].empty() ||
                operations[t-'a'][0] > (count[t-'a']+1) )
            {
                cout << t;
                count[t-'a']++;
            }
            else {
                operations[t-'a'].pop_front();
            }
            i++;
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <deque>

using namespace std;

typedef int IntType;
typedef deque<IntType> IntVector;
typedef IntVector::iterator IntIterator;

IntIterator findLowest( IntIterator begin, IntIterator end ) {
    IntIterator iter, min = begin;

    for( iter = begin; iter != end; ++iter ) {
        if( (*iter) < (*min) )
            min = iter;
    }
    return min;
}

int main( int, char** ) {
    int k, n;
    string s;

    cin >> k >> s >> n;

    IntVector operations[30];

    for( int i=0; i < n; ++i ) {
        IntType p;
        char t;

        cin >> p >> t;

        operations[t-'a'].push_back(p);
    }

    // sort
    for( int i=0; i < 30; ++i ) {
        IntVector &Operations = operations[i];

        IntVector Sorted;
        while( !Operations.empty() ) {

            IntIterator least = findLowest(Operations.begin(), Operations.end() );
            IntType Value = *least;

            for( IntIterator iter=Operations.begin(); iter != least; ++iter ) {
                (*iter)--;
            }

            Operations.erase(least);
            Sorted.push_back(Value);
        }
        Operations = Sorted;
    }

    long long count[30];

    for( int i=0; i < 30; ++i ) {
        count[i] = 0;
    }

    long long length = k*s.size();
    for( long long i=0; i < length; ) {
        for( int a=0; a < s.size(); ++a ) {
            char t = s[a];

            if( operations[t-'a'].empty() ||
                operations[t-'a'][0] > (count[t-'a']+1) )
            {
                cout << t;
                count[t-'a']++;
            }
            else {
                operations[t-'a'].pop_front();
            }
            i++;
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <deque>

using namespace std;

typedef int IntType;
typedef deque<IntType> IntVector;
typedef IntVector::iterator IntIterator;

IntIterator findLowest( IntIterator begin, IntIterator end ) {
    IntIterator iter, min = begin;

    for( iter = begin; iter != end; ++iter ) {
        if( (*iter) < (*min) )
            min = iter;
    }
    return min;
}

int main( int, char** ) {
    int k, n;
    string s;

    cin >> k >> s >> n;

    IntVector operations[30];

    for( int i=0; i < n; ++i ) {
        IntType p;
        char t;

        cin >> p >> t;

        operations[t-'a'].push_back(p);
    }

    // sort
    for( int i=0; i < 30; ++i ) {
        IntVector &Operations = operations[i];

        IntIterator SortedTo = Operations.begin();

        while( SortedTo != Operations.end() ) {
            IntIterator last = findLowest(SortedTo, Operations.end() );
            if( last == SortedTo ) {
                SortedTo++;
                continue;
            }
            for( IntIterator iter=SortedTo; iter != last; ++iter ) {
                (*iter)--;
            }

            IntType Value = *last;
            Operations.erase(last);
            Operations.insert( SortedTo, Value );

            SortedTo++;
        }
    }
/*
    for_each( operations[0].begin(), operations[0].end(), [](IntType i) {
        cout << i << endl;
    } );
 */

    long long count[30];

    for( int i=0; i < 30; ++i ) {
        count[i] = 0;
    }

    long long length = k*s.size();
    for( long long i=0; i < length; ) {
        for( int a=0; a < s.size(); ++a ) {
            char t = s[a];
            count[t-'a']++;

            if( operations[t-'a'].empty() ||
                operations[t-'a'][0] > count[t-'a'] ) {
                cout << t;
            }
            else {
                operations[t-'a'].pop_front();
            }
            i++;
        }
    }
    cout << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main( int, char** ) {
    int k, n;
    string s;

    cin >> k >> s >> n;

    string Answer;
    Answer.reserve( k*s.size()+1 );

    for( int i=0; i < k; ++i ) {
        Answer += s;
    }

    for( int i=0; i < n; ++i ) {
        int p, c = 0;
        char tek;

        cin >> p >> tek;

        string::iterator iter;

        for( iter = Answer.begin(); iter != Answer.end(); ++iter ) {
            if( (*iter) == tek ) {
                c++;
            }
            if( c == p ) break;
        }

        Answer.erase( iter );
    }

    cout << Answer << endl;

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#define LT(i) ((i) << 1)
#define RT(i) (((i) << 1) | 1)
#define MID(i) ((l[i] + r[i]) >> 1)
#define REP(i, l, n) for(int i = l;i < int(n);++i)
using namespace std;

const int N = 400020;
int sum[N << 2], l[N << 2], r[N << 2];
char str[N], buf[N];
void rebuild(int ll, int rr, int n, char ch)
{
    l[n] = ll, r[n] = rr;
    if(ll == rr)
    {
        sum[n] = (ch == str[ll]);
        return;
    }
    int mid = MID(n);
    rebuild(ll, mid, LT(n), ch);
    rebuild(mid + 1, rr, RT(n), ch);
    sum[n] = sum[LT(n)] + sum[RT(n)];
}
void travel(int ll, int rr, int n, char ch)
{
    if(ll == rr)
    {
        if(ch == str[ll] && sum[n] == 0)
        {
            str[ll] = 0;
        }
        return;
    }
    int mid = MID(n);
    travel(ll, mid, LT(n), ch);
    travel(mid + 1, rr, RT(n), ch);
}
void del(int n, int k)
{
    if(l[n] == r[n])
    {
        sum[n]--;
        return;
    }
    int suml = sum[LT(n)];
    if(suml >= k)
        del(LT(n), k);
    else
        del(RT(n), k - suml);
    sum[n] = sum[LT(n)] + sum[RT(n)];
}
const int ALP = 26;
vector<int> order[ALP];
int main()
{
    int k, len, cmd, pos;
    char ch;
    while(scanf("%d%s", &k, str) == 2)
    {
        len = strlen(str);
        REP(i, 1, k)
        {
            memcpy(str + len * i, str, sizeof(char) * len);
        }
        str[len * k] = 0;
        REP(i, 0, ALP) order[i].clear();
        scanf("%d", &cmd);
        REP(i, 0, cmd)
        {
            scanf("%d %c", &pos, &ch);
            order[ch - 'a'].push_back(pos);
        }
        REP(i, 0, ALP)
        {
            rebuild(0, len * k - 1, 1, 'a' + i);
            for(int j: order[i])
            {
                del(1, j);
            }
            travel(0, len * k - 1, 1, 'a' + i);
        }
        int buf_ptr = 0;
        for(int i = 0;i < len * k;i++)
        {
            if(str[i]) buf[buf_ptr++] = str[i];
        }
        buf[buf_ptr] = 0;
        printf("%s\n", buf);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

string lol(string s, int p, char c){
    int k = 0;
    int i;
    //cout << s << endl;
    for (i = 0; i < s.size(); i++){
        if (s[i] == c){
            k++;
            //cout << s[i] << i<< endl;
        }
        if (k == p){
            //cout << k << i;
            s.erase(i,1);
    //cout << s << endl;
    return(s);}}
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    string s;
    char c;
    int k, n, p;
    cin >> k;
    cin >> s;
    int k1 = s.size();
    s.resize(k*k1);
    for (int i = k1; i < s.size(); i++){
        s[i] = s[i-k1];
    }
    //cout << s;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> p >> c;
       // cout << p << c << endl;
        s = lol(s, p, c);
    }
    cout << s;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int a[2000][1000];
int b[1000];
int lol[5000][5000];

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    string s;
    char c;
    int k, n, p, l = 0, tr;
    cin >> k >> s >> n;
    for (int i = 0; i < s.size(); i++)
        b[s[i]]++;
    for (int i = 0; i < k; i++)
        for (int j = 0; j < s.size(); j++)
            a[i][s[j]] = b[s[j]];

    for (int i = 0; i < n; i++){
        cin >> p >> c;
        l = 0;
       	tr = 0;
        while (tr + a[l][c] < p){
            tr += a[l][c];
			l++;
        }
        for (int j = 0; j < s.size(); j++) {
           	if (lol[l][j] == -1)
                continue;
            if (s[j] == c)
                tr++;
			if (tr == p) {
			    lol[l][j] = -1;
				a[l][s[j]]--;
				break;
			}
		}
	}
    for (int i = 0; i < k; i++){
        for (int j = 0; j < s.size(); j++){
            if (lol[i][j] != -1)
                cout << s[j];
        }
    }

}


#include <cstdio>
#include <iostream>

#include <vector>
#include <list>
#include <string>

#include <algorithm>
#include <functional>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

size_t k;
string s;

char t[2010][110];
int d[2010][300];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> k >> s;

    for(size_t i = 0; i < k; ++i)
        for(size_t j = 0; j < s.size(); ++j) {
            t[i][j] = s[j];
            d[i][s[j]]++;
        }

    int n;
    cin >> n;

    while(n-- > 0) {
        int p;
        string c;

        cin >> p >> c;

        int q = 0;
        for(size_t i = 0; q < p && i < k; ++i) {

            if((q + d[i][c[0]]) >= p) {
                for(size_t j = 0; q < p && j < s.size(); ++j) {
                    if(t[i][j] == c[0])
                        ++q;

                    if(q == p) {
                        t[i][j] = 0;
                        d[i][c[0]]--;
                    }
                }
            }

            q += d[i][c[0]];
        }
    }

    for(size_t i = 0; i < k; ++i)
        for(size_t j = 0; j < s.size(); ++j)
            if(t[i][j] != 0)
                cout << t[i][j];
    cout << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

bool del[26][200001];

int ctr[26];

int arr[26];

int main()
{
    int k ;
    char x[102] ;
    string s ;
    scanf("%d",&k);
    scanf("%s",x);
    s = string(x);
    int n ,k1;
    char k2;
    scanf("%d",&n);
    vector<vector<int> > V;
    V.resize(26);
    for ( int j = 0 ; j < k ; j++ ) {
    for ( int i = 0 ; i < s.size() ; i++ ) {
        V[s[i]-'a'].push_back(++arr[s[i]-'a']);
    }
    }
    while ( n-- ) {
        scanf("%d %c",&k1,&k2);
        while ( V[k2-'a'][k1-1] == -1 ) {
            k1++;
        }
        del[k2-'a'][V[k2-'a'][k1-1]] = 1 ;
        V[k2-'a'][k1-1] = -1 ;

    }
    while ( k-- ) {
        for ( int i = 0 ; i < s.size() ; i++ ) {
            ctr[s[i]-'a']++;
            if ( !del[s[i]-'a'][ctr[s[i]-'a']] ) printf("%c",s[i]) ;
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

bool del[26][200001];

int ctr[26];

int main()
{
    vector< vector<int > > V ;
    V.resize(26);
    int k ;
    char x[102] ;
    string s ;
    scanf("%d",&k);
    scanf("%s",x);
    s = string(x);
    int n ,k1;
    char k2;
    scanf("%d",&n);
    for ( int i = 0 ; i < 26 ; i++ ) {
        for ( int j = 0 ; j < 200000 ; j++ )
            V[i].push_back(j+1) ;
    }
    while ( n-- ) {
        scanf("%d %c",&k1,&k2);
        del[k2-'a'][V[k2-'a'][k1-1]] = 1 ;
        V[k2-'a'].erase(V[k2-'a'].begin()+k1-1) ;
    }
    while ( k-- ) {
        for ( int i = 0 ; i < s.size() ; i++ ) {
            ctr[s[i]-'a']++;
            if ( !del[s[i]-'a'][ctr[s[i]-'a']] ) printf("%c",s[i]) ;
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;
bool del[26][200001];
int ctr[26];
int arr[26];
int main()
{
    int k ;
    char x[102] ;
    string s ;
    scanf("%d",&k);
    scanf("%s",x);
    s = string(x);
    int n ,k1;
    char k2;
    scanf("%d",&n);
    while ( n-- ) {
        scanf("%d %c",&k1,&k2);
        del[k2-'a'][k1+arr[k2-'a']] = 1 ;
        arr[k2-'a']++;
    }
    while ( k-- ) {
        for ( int i = 0 ; i < s.size() ; i++ ) {
            ctr[s[i]-'a']++;
            if ( !del[s[i]-'a'][ctr[s[i]-'a']] ) printf("%c",s[i]) ;
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

bool del[26][200001];

int ctr[26];
int lol[26];
int main()
{
    int k ;
    char x[102] ;
    string s ;
    scanf("%d",&k);
    scanf("%s",x);
    s = string(x);
    int n ,k1;
    char k2;
    scanf("%d",&n);
    vector< vector<int > > V ;
    V.resize(26);
    for ( int j = 0  ; j < k ; j++ ) {
    for ( int i = 0 ; i < s.size() ; i++) {
        V[s[i]-'a'].push_back(++lol[s[i]-'a'] ) ;
    }
    }
    while ( n-- ) {
        scanf("%d %c",&k1,&k2);
        del[k2-'a'][V[k2-'a'][k1-1]] = 1 ;
        V[k2-'a'].erase(V[k2-'a'].begin()+k1-1);
    }
    while ( k-- ) {
        for ( int i = 0 ; i < s.size() ; i++ ) {
            ctr[s[i]-'a']++;
            if ( !del[s[i]-'a'][ctr[s[i]-'a']] ) printf("%c",s[i]) ;
        }
    }
    return 0;
}


#include <iostream>
#include <ctime>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <utility>
#include <cctype>

using namespace std;

#define FORALL(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORB(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef long double ld;
typedef complex<int> vec;

typedef pair<int,int> pii;
typedef map<int,int> mii;

#define pb push_back
#define mp make_pair

int main(){
	int TEST;
	cin >> TEST;
	FOR(test,TEST){
		ld a,b;
		cin >> a >> b;
		if (b<0.5){
			cout << "1.000000000" << endl;
			return 0;
		}

		if (a < 0.5){
			cout << "0.5000000" << endl;
			return 0;
		}

		ld ans = b*a;
		if (b>a/4){
			ans += a*(a/4.)/2.;
		}else{
			//ld z = 4*(a/4-b);
			//ans += (a+z)*b/2.0;
			ans += b*a;
			ans -= b*4*b/2.;
		}
		ans /= 2*(a*b);
		cout << fixed << setprecision(9) << ans << endl;
	}
}


#include <iostream>
#include <ctime>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <utility>
#include <cctype>

using namespace std;

#define FORALL(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORB(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef long double ld;
typedef complex<int> vec;

typedef pair<int,int> pii;
typedef map<int,int> mii;

#define pb push_back
#define mp make_pair

int main(){
	int TEST;
	cin >> TEST;
	FOR(test,TEST){
		ld a,b;
		cin >> a >> b;
		ld ans = b*a;
		if (b>a/4){
			ans += a*(a/4.)/2.;
		}else{
			ld z = 4*(a/4-b);
			ans += (a+z)*b/2.0;
		}
		ans /= 2*(a*b);
		cout << fixed << setprecision(9) << ans << endl;
	}
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(p<=0 || p>=10 || q<0 || q>=10)
      while(1);
    if(q==0)
    {
      //case 2
      printf("%.10lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)q*q*2;
    printf("%.10lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs;
double p,q,h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%lf%lf",&p,&q);
    if(q==0)
    {
      //case 2
      if(p==0)
        while(1);
      printf("%.10lf\n",1);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=p*p/8;
    else
      a=q*q*2;
    printf("%.15lf\n",.5+.5*a/(p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(p<=0 || p>=10 || q<0 || q>=10)
      while(1);
    if(q==0)
    {
      //case 2
      printf("%.10lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)p*q-(double)q*q*2;
    printf("%.10lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(q==0)
    {
      //case 2
      while(1);
      printf("%.10lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)q*q*2;
    printf("%.15lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs;
double p,q,h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%lf%lf",&p,&q);
    if(q==0)
    {
      //case 2
      if(p==0)
        while(1);
      printf("%.10lf\n",0.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=p*p/8;
    else
      a=q*q*2;
    printf("%.15lf\n",.5+.5*a/(p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(p<=0 || p>=10 || q<0 || q>=10)
      while(1);
    if(q==0)
    {
      //case 2
      printf("%.15lf\n",0.);
      continue;
    }
    if(p==0)
    {
      printf("%.15lf\n",0.);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)q*q*2;
    printf("%.15lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(q==0)
    {
      //case 2
      printf("%.15lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.15lf\n",0.);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)q*q*2;
    printf("%.15lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&q,&p);
    if(p<=0 || p>=10 || q<0 || q>=10)
      while(1);
    if(q==0)
    {
      //case 2
      printf("%.10lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)q*q*2;
    printf("%.10lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs;
double p,q,h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%lf%lf",&p,&q);
    if(q==0)
    {
      //case 2
      if(p==0)
        while(1);
      printf("%.10lf\n",.5);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=p*p/8;
    else
      a=q*q*2;
    printf("%.15lf\n",.5+.5*a/(p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(q==0)
    {
      //case 2
      printf("%.15lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.15lf\n",1.);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)q*q*2;
    printf("%.15lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs;
double p,q,h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%lf%lf",&p,&q);
    if(q==0)
    {
      while(1);
      printf("1\n");
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=p*p/8;
    else
      a=q*q*2;
    printf("%.15lf\n",.5+.5*a/(p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs,p,q;
double a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%d%d",&p,&q);
    if(q==0)
    {
      //case 2
      printf("%.10lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=(double)p*p/8.;
    else
      a=(double)p*q-(double)q*q*2;
    printf("%.10lf\n",.5+.5*a/((double)p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs;
double p,q,h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%lf%lf",&p,&q);
    if(q==0)
    {
      //case 2
      if(p==0)
        while(1);
      printf("%.10lf\n",1.);
      continue;
    }
    if(p==0)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=p*p/8;
    else
      a=q*q*2;
    printf("%.15lf\n",.5+.5*a/(p*q));
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define p(x) cout<<#x<<":"<<x<<"\n"
#define eps 1e-10

int cs;
double p,q,h,a;

int main()
{
  scanf("%d",&cs);
  while(cs--)
  {
    scanf("%lf%lf",&p,&q);
    if(q<eps)
    {
      printf("1\n");
      continue;
    }
    if(p<eps)
    {
      printf("%.10lf\n",.5);
      continue;
    }
    if(p<4*q)
      a=p*p/8;
    else
      a=q*q*2;
    h=min(p,4*q);
    printf("%.10lf\n",.5+.5*a/(p*q));
  }
  return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back
#define setval(a,v) memset(a,v,sizeof(a))

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long int64;
typedef long double ld;

int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        int a,b;
        cin>>a>>b;
        if (b==0){
            printf("1\n");
            continue;
        }
        if (a==0){
            printf("0.5\n");
            return 0;
        }
        ld c = min(b*1.0,a/4.0);
        ld res = 0.5 + c/(2.0*b) - c*c/(a*b);
        cout.precision(15);
        cout<<fixed<<res<<endl;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back
#define setval(a,v) memset(a,v,sizeof(a))

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long int64;
typedef long double ld;

int main(){
  int t;
  cin>>t;
  for (int i=0;i<t;i++){
      int a,b;
      cin>>a>>b;
      if (b==0){
          printf("1\n");
          continue;
      }
      if (a==0){
          printf("0.5\n");
      continue;
      }
      ld c = min(b*1.0,a/4.0);
      ld res = 0.5 + c/(2.0*b) - c*c/(a*1LL*b);
      cout.precision(15);
      cout<<fixed<<res<<endl;
   }
   return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back
#define setval(a,v) memset(a,v,sizeof(a))

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long int64;
typedef long double ld;

int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        int a,b;
        cin>>a>>b;
        if (b==0){
            printf("1\n");
            continue;
        }
        if (a <= 4*b){
            cout.precision(15);
            cout<<fixed<<0.5+(a*1.0/(16*b))<<endl;
        }
        else {
            cout.precision(15);
            cout<<fixed<<(0.5+(b*1.0/a)+(a-4*b)*1.0/(2*a*b))<<endl;
        }
    }
    return 0;
}


   1. #include <iostream>
   2. #include <fstream>
   3. #include <vector>
   4. #include <set>
   5. #include <map>
   6. #include <string>
   7. #include <cmath>
   8. #include <cassert>
   9. #include <ctime>
  10. #include <algorithm>
  11. #include <queue>
  12. #include <memory.h>
  13. #include <stack>
  14. #define mp make_pair
  15. #define pb push_back
  16. #define setval(a,v) memset(a,v,sizeof(a))
  17.

  18. #if ( _WIN32 || __WIN32__ )
  19.     #define LLD "%I64d"
  20. #else
  21.     #define LLD "%lld"
  22. #endif
  23.

  24. using namespace std;
  25.

  26. typedef long long int64;
  27. typedef long double ld;
  28.

  29. int main()
  30. {
  31.   #ifndef ONLINE_JUDGE
  32.     freopen("input.txt","r",stdin);
  33.     freopen("output.txt","w",stdout);
  34.   #endif
  35.     int t;
  36.     cin>>t;
  37.     for (int i=0;i<t;i++){
  38.         int a,b;
  39.         cin>>a>>b;
  40.         if (b==0){
  41.             printf("1\n");
  42.             continue;
  43.         }
  44.         if (a==0){
  45.             printf("0.5\n");
  46.             return 0;
  47.         }
  48.         ld c = min(b*1.0,a/4.0);
  49.         ld res = 0.5 + c/(2.0*b) - c*c/(a*1LL*b);
  50.         cout.precision(15);
  51.         cout<<fixed<<res<<endl;
  52.     }
  53.     return 0;
  54. }


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back
#define setval(a,v) memset(a,v,sizeof(a))

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long int64;
typedef long double ld;

int main(){
  int t;
  cin>>t;
  for (int i=0;i<t;i++){
      int a,b;
      cin>>a>>b;
      if (b==0){
          printf("1\n");
          continue;
      }
      if (a==0){
          printf("0.5\n");
          return 0;
      }
      ld c = min(b*1.0,a/4.0);
      ld res = 0.5 + c/(2.0*b) - c*c/(a*1LL*b);
      cout.precision(15);
      cout<<fixed<<res<<endl;
   }
   return 0;
}


#include<iostream>
using namespace std;
int main(void)
{
	cout.precision(8);
	cout.setf(ios::fixed,ios::floatfield);
	int tts;
	cin>>tts;
	for(int tt=0;tt<tts;++tt)
	{
		double a,b;
		cin>>a>>b;
		double ans=0.5;
		if(a>4*b)
		{
			ans+=0.25;
			ans+=0.25*(4*b)/a;
		}
		else
			ans+=0.25*a/(4*b);
		cout<<ans<<endl;
	}
	return 0;
}
/****** PCCA -Tue Nov 29 11:05:56 GMT 2011 *******/


#include<iostream>
using namespace std;
int main(void)
{
	cout.precision(8);
	cout.setf(ios::fixed,ios::floatfield);
	int tts;
	cin>>tts;
	for(int tt=0;tt<tts;++tt)
	{
		double a,b;
		cin>>a>>b;
		double ans=0.5;
		if(a>4*b)
		{
			ans+=0.25;
			ans+=0.25*(4*b)/a;
		}
		else
			ans+=0.25*a/(4*b);
		cout<<ans<<endl;
	}
	return 0;
}
/****** PCCA -Tue Nov 29 11:05:40 GMT 2011 *******/


#include <iostream>
using namespace std;
int main(){
	int t;
	cin >> t;
	while( t -- ){
		int a, b;
		cin >> a >> b;
		if( b == 0 ){
			cout << 1.0 << endl;
		}else if( a <= 4 * b ){
			cout << 0.5 + ( (double)a ) / ( 16.0 * ( (double) b ) ) << endl;
		}else{
			cout << 0.5 + ( (double) ( 2*a-4*b ) ) / ( 4 * ( (double)a ) ) << endl;
		}
	}
	return 0;
}
/****** PCCA -Sun Aug 28 14:13:01 GMT 2011 *******/


#include<iostream>
using namespace std;
int main(void)
{
	cout.precision(8);
	cout.setf(ios::fixed,ios::floatfield);
	int tts;
	cin>>tts;
	for(int tt=0;tt<tts;++tt)
	{
		double a,b;
		cin>>a>>b;
		double ans=0.5;
		if(a>4*b)
		{
			ans+=0.25;
			ans+=0.25*(a-4*b)/a;
		}
		else
			ans+=0.25*a/(4*b);
		cout<<ans<<endl;
	}
	return 0;
}
/****** PCCA -Tue Nov 29 11:11:11 GMT 2011 *******/


#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
p-4*q>=0
p>=4*q
p>=4*(-b)
p>=4*b
*/
int main()
{
	int nT;
	scanf("%d",&nT);
	while(nT--)
	{
		double a,b;
		double minY=0,maxY;
		double maxX,minX;
		scanf("%lf%lf",&maxY,&maxX);
		minX=-maxX;
		double area=0;
		area+=(maxX-minX)*(maxY-minY);
		double upper;
		double height;
		if(4*maxX>maxY)
			upper=maxX-maxY/4,height=maxY;
		else
			upper=0,height=4*maxX;
		area-=(upper+maxX)*height/2;
		printf("%.8f\n",area/((maxY-minY)*(maxX-minX)));
	}
}
/****** PCCA -Tue Nov 29 11:19:11 GMT 2011 *******/


#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
p-4*q>=0
p>=4*q
p>=4*(-b)
p>=4*b
*/
int main()
{
	int nT;
	scanf("%d",&nT);
	while(nT--)
	{
		double minY=0,maxY;
		double maxX,minX;
		scanf("%lf%lf",&maxY,&maxX);
		if(maxX==0)
		{
			printf("%.8f\n",1.0);
			continue;
		}
		if(maxY==0)
		{
			printf("%.8f\n",0.5);
			continue;
		}
		minX=-maxX;
		double total=((maxY-minY)*(maxX-minX));
		double area=total;
		double upper;
		double height;
		if(4*maxX>maxY)
			upper=maxX-maxY/4,height=maxY;
		else
			upper=0,height=4*maxX;
		area-=(upper+maxX)*height/2;
		printf("%.8f\n",area/total);
	}
}
/****** PCCA -Tue Nov 29 13:25:45 GMT 2011 *******/


#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
p-4*q>=0
p>=4*q
p>=4*(-b)
p>=4*b
*/
int main()
{
	int nT;
	scanf("%d",&nT);
	while(nT--)
	{
		double minY=0,maxY;
		double maxX,minX;
		scanf("%lf%lf",&maxY,&maxX);
		if(maxX==0)
		{
			printf("%.8f\n",1.0);
			continue;
		}
		minX=-maxX;
		double total=((maxY-minY)*(maxX-minX));
		double area=total;
		double upper;
		double height;
		if(4*maxX>maxY)
			upper=maxX-maxY/4,height=maxY;
		else
			upper=0,height=4*maxX;
		area-=(upper+maxX)*height/2;
		printf("%.8f\n",area/total);
	}
}
/****** PCCA -Tue Nov 29 13:12:18 GMT 2011 *******/


#include<iostream>
using namespace std;
int main(void)
{
	cout.precision(10);
	cout.setf(ios::fixed,ios::floatfield);
	int tts;
	cin>>tts;
	for(int tt=0;tt<tts;++tt)
	{
		int a,b;
		cin>>a>>b;
		double ans=0.5;
		if(a==0&&b==0)
			ans=1.0;
		else if(a>=4*b)
		{
			ans+=0.25;
			ans+=0.25*(a-4*b)/a;
		}
		else
			ans+=0.25*a/(4*b);
		cout<<ans<<endl;
	}
	return 0;
}
/****** PCCA -Tue Nov 29 11:23:04 GMT 2011 *******/


#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
p-4*q>=0
p>=4*q
p>=4*(-b)
p>=4*b
*/
int main()
{
	int nT;
	scanf("%d",&nT);
	while(nT--)
	{
		double minY=0,maxY;
		double maxX,minX;
		scanf("%lf%lf",&maxY,&maxX);
		if(maxX==0)
		{
			printf("%.8f\n",1.0);
			continue;
		}
		if(maxY==0)
		{
			printf("%.8f\n",0.0);
			continue;
		}
		minX=-maxX;
		double total=((maxY-minY)*(maxX-minX));
		double area=total;
		double upper;
		double height;
		if(4*maxX>maxY)
			upper=maxX-maxY/4,height=maxY;
		else
			upper=0,height=4*maxX;
		area-=(upper+maxX)*height/2;
		printf("%.8f\n",area/total);
	}
}
/****** PCCA -Tue Nov 29 13:19:33 GMT 2011 *******/


#include<iostream>
using namespace std;
int main(void)
{
	cout.precision(10);
	cout.setf(ios::fixed,ios::floatfield);
	int tts;
	cin>>tts;
	for(int tt=0;tt<tts;++tt)
	{
		int a,b;
		cin>>a>>b;
		double ans=0.5;
		if(a>4*b)
		{
			ans+=0.25;
			ans+=0.25*(a-4*b)/a;
		}
		else
			ans+=0.25*a/(4*b);
		cout<<ans<<endl;
	}
	return 0;
}
/****** PCCA -Tue Nov 29 11:20:35 GMT 2011 *******/


#include<iostream>
#include<cstdio>
using namespace std;
int main() {
//    freopen("test.inp","r",stdin);
    int T;
    cin >> T;
    while (T--) {
        int a, b;
        cin >> a >> b;
        int x=min(4*b,a);
        double res=0.5+1.0*x*x/(16*b*a);
        if (4*b<=a) res+=0.5*(a-4*b)/a;
        cout << res << endl;
    }
}


#include<iostream>
#include<cstdio>
using namespace std;
int main() {
//    freopen("test.inp","r",stdin);
    int T;
    cin >> T;
    while (T--) {
        int a, b;
        cin >> a >> b;
        if (b==0) cout << 1 << endl;
        else if (a==0) cout << 1/2 << endl;
        else {
            int x=min(4*b,a);
            double res=0.5+1.0*x*x/(16*b*a);
            if (4*b<=a) res+=0.5*(a-4*b)/a;
            cout.precision(6);
            cout << fixed << res << endl;
        }
    }
}


#include<iostream>
#include<cstdio>
using namespace std;
int main() {
//    freopen("test.inp","r",stdin);
    int T;
    cin >> T;
    while (T--) {
        int a, b;
        cin >> a >> b;
        int x=min(4*b,a);
        double res=0.5+1.0*x*x/(16*b*a);
        if (4*b<=a) res+=0.5*(a-4*b)/a;
        cout.precision(6);
        cout << fixed << res << endl;
    }
}


#include<iostream>
#include<cstdio>
using namespace std;
int main() {
//    freopen("test.inp","r",stdin);
    int T;
    cin >> T;
    while (T--) {
        int a, b;
        cin >> a >> b;
        if (b==0) cout << 1 << endl;
        else if (a==0) cout << 0.5 << endl;
        else {
            int x=min(4*b,a);
            double res=0.5+1.0*x*x/(16*b*a);
            if (4*b<=a) res+=0.5*(a-4*b)/a;
            cout.precision(6);
            cout << fixed << res << endl;
        }
    }
}


#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main() {
//    freopen("test.inp","r",stdin);
    int T;
    cin >> T;
    while (T--) {
        ll a, b;
        cin >> a >> b;
        if (b==0) cout << 1 << endl;
        else if (a==0) cout << 0.5 << endl;
        else {
            ll x=min(4*b,a);
            double res=0.5+1.0*x*x/(16*b*a);
            if (4*b<=a) res+=0.5*(a-4*b)/a;
            cout.precision(6);
            cout << fixed << res << endl;
        }
    }
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX(a,b)    (((a)>(b))?(a):(b))
#define MIN(a,b)    (((a)<(b))?(a):(b))
#define FR(i,a,b)   for(int ( i)=(a); ( i)<(b); ++( i))
#define FRE(i,a,b)  for(int ( i)=(a); ( i)<=(b); ++( i))
#define FRD(i,a,b)  for(( i)=(a); ( i)<(b); ++( i))
#define FRI(i,a)    for(( i)=(a).begin(); ( i)!=(a).end(); ++( i))
#define SWAP(a,b,t) (t)=(a);(a)=(b);(b)=(t);

#define I long long
#define VI vector<int>
#define VL vector<I>
#define VD vector<double>
#define VLD vector<long double>
#define VS vector<string>
#define LI list<int>
#define LL list<I>
#define LD list<double>
#define LLD list<long double>
#define LS list<string>
#define SI set<int>
#define SL set<I>
#define SD set<double>
#define SLD set<long double>
#define SS set<string>
#define MII map<int,int>
#define MIL map<int,I>
#define MID map<int,double>
#define MIS map<int,string>
#define MLL map<I,I>
#define MLI map<I, int>
#define MLD map<I,double>
#define IT iterator

#define MMS(a) memset(a,0,sizeof(a))

int gcd(int a, int b)
{
    int c=min(a,b), d=max(a,b);
    while(c)
    {
        int t=d%c;
        d=c;
        c=t;
    }
    return d;
}

int main()
{
    int t;
    cin>>t;
    FR(i,0,t)
    {
        int a,b;
        cin>>a>>b;
        double r=0.0;

        if(b==0)
            r=1.0;
        else if(a/4.0<=b)
        {
            r=a/8.0;
            r = (r+b)/(2*b);
        }
        else
        {
            r=4.0*b/a;
        }
        cout<<r<<endl;
    }
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX(a,b)    (((a)>(b))?(a):(b))
#define MIN(a,b)    (((a)<(b))?(a):(b))
#define FR(i,a,b)   for(int ( i)=(a); ( i)<(b); ++( i))
#define FRE(i,a,b)  for(int ( i)=(a); ( i)<=(b); ++( i))
#define FRD(i,a,b)  for(( i)=(a); ( i)<(b); ++( i))
#define FRI(i,a)    for(( i)=(a).begin(); ( i)!=(a).end(); ++( i))
#define SWAP(a,b,t) (t)=(a);(a)=(b);(b)=(t);

#define I long long
#define VI vector<int>
#define VL vector<I>
#define VD vector<double>
#define VLD vector<long double>
#define VS vector<string>
#define LI list<int>
#define LL list<I>
#define LD list<double>
#define LLD list<long double>
#define LS list<string>
#define SI set<int>
#define SL set<I>
#define SD set<double>
#define SLD set<long double>
#define SS set<string>
#define MII map<int,int>
#define MIL map<int,I>
#define MID map<int,double>
#define MIS map<int,string>
#define MLL map<I,I>
#define MLI map<I, int>
#define MLD map<I,double>
#define IT iterator

#define MMS(a) memset(a,0,sizeof(a))

int gcd(int a, int b)
{
    int c=min(a,b), d=max(a,b);
    while(c)
    {
        int t=d%c;
        d=c;
        c=t;
    }
    return d;
}

int main()
{
    int t;
    cin>>t;
    FR(i,0,t)
    {
        int a,b;
        cin>>a>>b;
        double r=0.0;

        if(b==0)
            r=1.0;
        else if(a/4.0<=b)
        {
            r=a/8.0;
            r = (r+b)/(2*b);
        }
        else
        {
            r=0.75*4*b/a + 1.0*(a-4.0*b)/a;
        }
        printf("%0.9lf\n",r);
    }
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX(a,b)	(((a)>(b))?(a):(b))
#define MIN(a,b)	(((a)<(b))?(a):(b))
#define FR(i,a,b)	for(int ( i)=(a); ( i)<(b); ++( i))
#define FRE(i,a,b)	for(int ( i)=(a); ( i)<=(b); ++( i))
#define FRD(i,a,b)	for(( i)=(a); ( i)<(b); ++( i))
#define FRI(i,a)	for(( i)=(a).begin(); ( i)!=(a).end(); ++( i))
#define SWAP(a,b,t) (t)=(a);(a)=(b);(b)=(t);

#define I long long
#define VI vector<int>
#define VL vector<I>
#define VD vector<double>
#define VLD vector<long double>
#define VS vector<string>
#define LI list<int>
#define LL list<I>
#define LD list<double>
#define LLD list<long double>
#define LS list<string>
#define SI set<int>
#define SL set<I>
#define SD set<double>
#define SLD set<long double>
#define SS set<string>
#define MII map<int,int>
#define MIL map<int,I>
#define MID map<int,double>
#define MIS map<int,string>
#define MLL map<I,I>
#define MLI map<I, int>
#define MLD map<I,double>
#define IT iterator

#define MMS(a) memset(a,0,sizeof(a))

int gcd(int a, int b)
{
	int c=min(a,b), d=max(a,b);
	while(c)
	{
		int t=d%c;
		d=c;
		c=t;
	}
	return d;
}

int main()
{
	int t;
	cin>>t;
	FR(i,0,t)
	{
		int a,b;
		cin>>a>>b;
		double r=0.0;

		if(a/4<=b)
			r=a/8.0;
		else
			r=b/8.0;
		cout<<(r+b)/(2*b)<<endl;
	}
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX(a,b)    (((a)>(b))?(a):(b))
#define MIN(a,b)    (((a)<(b))?(a):(b))
#define FR(i,a,b)   for(int ( i)=(a); ( i)<(b); ++( i))
#define FRE(i,a,b)  for(int ( i)=(a); ( i)<=(b); ++( i))
#define FRD(i,a,b)  for(( i)=(a); ( i)<(b); ++( i))
#define FRI(i,a)    for(( i)=(a).begin(); ( i)!=(a).end(); ++( i))
#define SWAP(a,b,t) (t)=(a);(a)=(b);(b)=(t);

#define I long long
#define VI vector<int>
#define VL vector<I>
#define VD vector<double>
#define VLD vector<long double>
#define VS vector<string>
#define LI list<int>
#define LL list<I>
#define LD list<double>
#define LLD list<long double>
#define LS list<string>
#define SI set<int>
#define SL set<I>
#define SD set<double>
#define SLD set<long double>
#define SS set<string>
#define MII map<int,int>
#define MIL map<int,I>
#define MID map<int,double>
#define MIS map<int,string>
#define MLL map<I,I>
#define MLI map<I, int>
#define MLD map<I,double>
#define IT iterator

#define MMS(a) memset(a,0,sizeof(a))

int gcd(int a, int b)
{
    int c=min(a,b), d=max(a,b);
    while(c)
    {
        int t=d%c;
        d=c;
        c=t;
    }
    return d;
}

int main()
{
    int t;
    cin>>t;
    FR(i,0,t)
    {
        int a,b;
        cin>>a>>b;
        double r=0.0;

        if(a/4<=b)
        {
            r=a/8.0;
            r = (r+b)/(2*b);
        }
        else
        {
            r=4.0*b/a;
        }
        cout<<r<<endl;
    }
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX(a,b)    (((a)>(b))?(a):(b))
#define MIN(a,b)    (((a)<(b))?(a):(b))
#define FR(i,a,b)   for(int ( i)=(a); ( i)<(b); ++( i))
#define FRE(i,a,b)  for(int ( i)=(a); ( i)<=(b); ++( i))
#define FRD(i,a,b)  for(( i)=(a); ( i)<(b); ++( i))
#define FRI(i,a)    for(( i)=(a).begin(); ( i)!=(a).end(); ++( i))
#define SWAP(a,b,t) (t)=(a);(a)=(b);(b)=(t);

#define I long long
#define VI vector<int>
#define VL vector<I>
#define VD vector<double>
#define VLD vector<long double>
#define VS vector<string>
#define LI list<int>
#define LL list<I>
#define LD list<double>
#define LLD list<long double>
#define LS list<string>
#define SI set<int>
#define SL set<I>
#define SD set<double>
#define SLD set<long double>
#define SS set<string>
#define MII map<int,int>
#define MIL map<int,I>
#define MID map<int,double>
#define MIS map<int,string>
#define MLL map<I,I>
#define MLI map<I, int>
#define MLD map<I,double>
#define IT iterator

#define MMS(a) memset(a,0,sizeof(a))

int gcd(int a, int b)
{
    int c=min(a,b), d=max(a,b);
    while(c)
    {
        int t=d%c;
        d=c;
        c=t;
    }
    return d;
}

int main()
{
    int t;
    cin>>t;
    FR(i,0,t)
    {
        int a,b;
        cin>>a>>b;
        double r=0.0;

        if(b==0)
            r=1.0;
        else if(a/4.0<=b)
        {
            r=a/8.0;
            r = (r+b)/(2*b);
        }
        else
        {
            r=4.0*b/a;
        }
        printf("%0.9lf\n",r);
    }
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX(a,b)    (((a)>(b))?(a):(b))
#define MIN(a,b)    (((a)<(b))?(a):(b))
#define FR(i,a,b)   for(int ( i)=(a); ( i)<(b); ++( i))
#define FRE(i,a,b)  for(int ( i)=(a); ( i)<=(b); ++( i))
#define FRD(i,a,b)  for(( i)=(a); ( i)<(b); ++( i))
#define FRI(i,a)    for(( i)=(a).begin(); ( i)!=(a).end(); ++( i))
#define SWAP(a,b,t) (t)=(a);(a)=(b);(b)=(t);

#define I long long
#define VI vector<int>
#define VL vector<I>
#define VD vector<double>
#define VLD vector<long double>
#define VS vector<string>
#define LI list<int>
#define LL list<I>
#define LD list<double>
#define LLD list<long double>
#define LS list<string>
#define SI set<int>
#define SL set<I>
#define SD set<double>
#define SLD set<long double>
#define SS set<string>
#define MII map<int,int>
#define MIL map<int,I>
#define MID map<int,double>
#define MIS map<int,string>
#define MLL map<I,I>
#define MLI map<I, int>
#define MLD map<I,double>
#define IT iterator

#define MMS(a) memset(a,0,sizeof(a))

int gcd(int a, int b)
{
    int c=min(a,b), d=max(a,b);
    while(c)
    {
        int t=d%c;
        d=c;
        c=t;
    }
    return d;
}

int main()
{
    int t;
    cin>>t;
    FR(i,0,t)
    {
        int a,b;
        cin>>a>>b;
        double r=0.0;

        if(a/4<=b)
        {
            if(b==0)
                r=1.0;
            else
            {
                r=a/8.0;
                r = (r+b)/(2*b);
            }
        }
        else
        {
            r=4.0*b/a;
        }
        cout<<r<<endl;
    }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <complex>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define SET_DIFF(x,y,z) set_difference(all(x) , all(y) , back_inserter(z))
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

// -b +- root(b2 - 4ac) / 2a
// a = 1, b = root(p), c = q
// b2 - 4ac >= 0
// p - 4q >= 0
// q = p/4
// line (0,0) to (a,a/4)
// Area of rectangle = 0.5 * base * height

int main() {
  int t, a, b;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (b == 0)
      puts("1.0");
    else if (a == 0)
      puts("0.5");
    else {
      double tot = (ll) a * b * 2.0;
      double ans = (ll) a * b + (ll) a * (a / 8.0)
          - ((a / 4.0 <= b) ? 0.0 : (ll) (a - 4 * b) * (a / 4.0 - b) * 0.5);
      printf("%.6lf\n", ans / tot);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <complex>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define SET_DIFF(x,y,z) set_difference(all(x) , all(y) , back_inserter(z))
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

typedef complex<double> point;
#define X real()
#define Y imag()
#define vec(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())

double polygonArea(const vector<point>&p) {
  double res = 0;
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    res += cross(p[i], p[j]);
  }
  return fabs(res) / 2;
}

bool intersect(const point &a, const point &b, const point &p, const point &q,
    point &ret) {
  double d1 = cross(p - a, b - a);
  double d2 = cross(q - a, b - a);
  ret = (d1 * q - d2 * p) / (d1 - d2);
  if (fabs(d1 - d2) > eps)
    return 1;
  return 0;
}

void polygonCut(const vector<point>& p, const point&a, const point&b,
    vector<point>& res) {
  res.clear();
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    bool in1 = cross(vec(a,b),vec(a,p[i])) > eps;
    bool in2 = cross(vec(a,b),vec(a,p[j])) > eps;
    if (!in1)
      res.pb(p[i]);
    if (in1 ^ in2) {
      point r;
      intersect(a, b, p[i], p[j], r);
      res.push_back(r);
    }
  }
}

// -b +- root(b2 - 4ac) / 2a
// a = 1, b = root(p), c = q
// b2 - 4ac >= 0
// p - 4q >= 0
// q = p/4
// line (0,0) to (a,a/4)
int main() {
  int t, a, b;
  vector<point> V(4);
  vector<point> tmp;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (b == 0)
      puts("1.0");
    else if (a == 0)
      puts("0.5");
    else {
      double tot = (ll) a * b * 2.0;
      point P0(a, -b);
      point P1(a, b);
      point P2(0, b);
      point P3(0, -b);
      V[0] = P0, V[1] = P1, V[2] = P2, V[3] = P3;
      point A0(0, 0), A1(a, a / 4.0);
      polygonCut(V, A0, A1, tmp);
      printf("%.6lf\n", polygonArea(tmp) / tot);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <complex>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define SET_DIFF(x,y,z) set_difference(all(x) , all(y) , back_inserter(z))
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

typedef complex<double> point;
#define X real()
#define Y imag()
#define vec(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())

double polygonArea(const vector<point>&p) {
  double res = 0;
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    res += cross(p[i], p[j]);
  }
  return fabs(res) / 2;
}

bool intersect(const point &a, const point &b, const point &p, const point &q,
    point &ret) {
  double d1 = cross(p - a, b - a);
  double d2 = cross(q - a, b - a);
  ret = (d1 * q - d2 * p) / (d1 - d2);
  if (fabs(d1 - d2) > eps)
    return 1;
  return 0;
}

void polygonCut(const vector<point>& p, const point&a, const point&b,
    vector<point>& res) {
  res.clear();
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    bool in1 = cross(vec(a,b),vec(a,p[i])) > eps;
    bool in2 = cross(vec(a,b),vec(a,p[j])) > eps;
    if (!in1)
      res.pb(p[i]);
    if (in1 ^ in2) {
      point r;
      intersect(a, b, p[i], p[j], r);
      res.push_back(r);
    }
  }
}
/*
 // Cut polygon P(anti-clock) by line AB
 // If polygon is clockwise, swap first, last lines
 // right is the right polygon on right hand side of AB
 // Make sure from polygon and line directions
 pair<vector<point>, vector<point> > polygonCut(vector<point> &p, point A, point B) {
 vector<point> left, right;
 point intersect;

 for (int i = 0; i < sz(p); ++i) {
 point cur = p[i], nxt = p[(i+1)%sz(p)];

 if ( cp(B-A, cur-A) >= 0) right.push_back(cur);

 if(intersectSegments(A, B, cur, nxt, intersect)) { //NOTE: AB should be handled as line
 right.push_back(intersect);
 left.push_back(intersect);
 }

 if ( cp(B-A, cur-A) <= 0) left.push_back(cur);
 }
 return make_pair(left, right);
 }
 *
 */

// -b +- root(b2 - 4ac) / 2a
// a = 1, b = root(p), c = q
// b2 - 4ac >= 0
// p - 4q >= 0
// q = p/4
// line (0,0) to (a,a/4)
int main() {
  int t, a, b;
  vector<point> V(4);
  vector<point> tmp;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    double tot = a * b * 2.0;
    point P0(a, -b);
    point P1(a, b);
    point P2(0, b);
    point P3(0, -b);
    V[0] = P0, V[1] = P1, V[2] = P2, V[3] = P3;
    point A0(0, 0), A1(a, min(a / 4.0, (double) b));
    polygonCut(V, A0, A1, tmp);
    printf("%.6lf\n", polygonArea(tmp) / tot);
  }
  return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <complex>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define SET_DIFF(x,y,z) set_difference(all(x) , all(y) , back_inserter(z))
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

typedef complex<double> point;
#define X real()
#define Y imag()
#define vec(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())

double polygonArea(const vector<point>&p) {
  double res = 0;
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    res += cross(p[i], p[j]);
  }
  return fabs(res) / 2;
}

bool intersect(const point &a, const point &b, const point &p, const point &q,
    point &ret) {
  double d1 = cross(p - a, b - a);
  double d2 = cross(q - a, b - a);
  ret = (d1 * q - d2 * p) / (d1 - d2);
  if (fabs(d1 - d2) > eps)
    return 1;
  return 0;
}

void polygonCut(const vector<point>& p, const point&a, const point&b,
    vector<point>& res) {
  res.clear();
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    bool in1 = cross(vec(a,b),vec(a,p[i])) > eps;
    bool in2 = cross(vec(a,b),vec(a,p[j])) > eps;
    if (!in1)
      res.pb(p[i]);
    if (in1 ^ in2) {
      point r;
      intersect(a, b, p[i], p[j], r);
      res.push_back(r);
    }
  }
}

// -b +- root(b2 - 4ac) / 2a
// a = 1, b = root(p), c = q
// b2 - 4ac >= 0
// p - 4q >= 0
// q = p/4
// line (0,0) to (a,a/4)
int main() {
  int t, a, b;
  vector<point> V(4);
  vector<point> tmp;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (b == 0)
      puts("1.0");
    else if (a == 0)
      puts("0.5");
    else {
      double tot = a * b * 2.0;
      point P0(a, -b);
      point P1(a, b);
      point P2(0, b);
      point P3(0, -b);
      V[0] = P0, V[1] = P1, V[2] = P2, V[3] = P3;
      point A0(0, 0), A1(a, min(a / 4.0, (double) b));
      polygonCut(V, A0, A1, tmp);
      printf("%.6lf\n", polygonArea(tmp) / tot);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <complex>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define SET_DIFF(x,y,z) set_difference(all(x) , all(y) , back_inserter(z))
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

typedef complex<double> point;
#define X real()
#define Y imag()
#define vec(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())

double polygonArea(const vector<point>&p) {
  double res = 0;
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    res += cross(p[i], p[j]);
  }
  return fabs(res) / 2;
}

bool intersect(const point &a, const point &b, const point &p, const point &q,
    point &ret) {
  double d1 = cross(p - a, b - a);
  double d2 = cross(q - a, b - a);
  ret = (d1 * q - d2 * p) / (d1 - d2);
  if (fabs(d1 - d2) > eps)
    return 1;
  return 0;
}

void polygonCut(const vector<point>& p, const point&a, const point&b,
    vector<point>& res) {
  res.clear();
  for (int i = 0; i < SZ(p); i++) {
    int j = (i + 1) % SZ(p);
    bool in1 = cross(vec(a,b),vec(a,p[i])) > eps;
    bool in2 = cross(vec(a,b),vec(a,p[j])) > eps;
    if (!in1)
      res.pb(p[i]);
    if (in1 ^ in2) {
      point r;
      intersect(a, b, p[i], p[j], r);
      res.push_back(r);
    }
  }
}

// -b +- root(b2 - 4ac) / 2a
// a = 1, b = root(p), c = q
// b2 - 4ac >= 0
// p - 4q >= 0
// q = p/4
// line (0,0) to (a,a/4)
int main() {
  int t, a, b;
  vector<point> V(4);
  vector<point> tmp;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (b == 0)
      puts("1.0");
    else if (a == 0)
      puts("0.5");
    else {
      double tot = a * b * 2.0;
      point P0(a, -b);
      point P1(a, b);
      point P2(0, b);
      point P3(0, -b);
      V[0] = P0, V[1] = P1, V[2] = P2, V[3] = P3;
      point A0(0, 0), A1(a, a / 4.0);
      polygonCut(V, A0, A1, tmp);
      printf("%.6lf\n", polygonArea(tmp) / tot);
    }
  }
  return 0;
}


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    int a, b; cin >> a >> b;
    if (a == 0 and b) { printf("0.5000000000\n"); continue ; }
    if (a == 0 and b == 0) { printf("1.000000000\n"); continue; }
    if (a and b == 0) { printf("1.000000000\n"); continue; }
    double all = a * 2. * b;
    double hit;
    if (b > a / 4) {
      hit = (b + b + a / 4.) * a / 2.;
    } else {
      hit = (all - 4. * b * b / 2.);
    }
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    int a, b; cin >> a >> b;
    if (b == 0) printf("1.000000000\n");
    if (a == 0) printf("1.000000000\n");
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    double a, b; cin >> a >> b;
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    double a, b; cin >> a >> b;
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    if (b < eps) printf("1.000000000\n");
    if (a < eps) printf("1.000000000\n");
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    int a, b; cin >> a >> b;
    if (a == 0 and b) { printf("0.5000000000\n"); continue ; }
    if (a == 0 and b == 0) { printf("1.000000000\n"); continue; }
    if (a and b == 0) { printf("1.000000000\n"); continue; }
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    int a, b; cin >> a >> b;
    if (a == 0 and b) printf("0.5\n");
    if (b == 0) printf("1.000000000\n");
    if (a == 0) printf("1.000000000\n");
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    int a, b; cin >> a >> b;
    if (a == 0 and b) printf("0.5\n");
    if (a == 0 and b == 0) printf("1.000000000\n");
    if (a and b == 0) printf("1.000000000\n");
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    int a, b; cin >> a >> b;
    if (a == 0 and b) { printf("0.5\n"); continue ; }
    if (a == 0 and b == 0) { printf("1.000000000\n"); continue; }
    if (a and b == 0) { printf("1.000000000\n"); continue; }
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#if 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <cctype>
#include <cassert>

#define REP(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define rep(i,b)   REP(i,0,b)
#define FOR(i,c)   for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c)     (c).begin(), (c).end()

using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int inf = 1<<25;

int main () {
  int i, j, k;

  int tc; cin >> tc;

  for (;tc--;) {
    double a, b; cin >> a >> b;
    double all = a * 2. * b;
    double hit = (b + b + a / 4.) * a / 2.;
    double res = hit / all;
    if (b < eps) printf("1\n");
    if (a < eps) printf("1\n");
    printf("%.10f\n", res);
  }

  cout.flush();
  return 0;
}

#endif


#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    long double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        if (b == 0) cout << 1 << endl;
        else cout << (a+8*b)/(16*b) << endl;
    }
}


#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    long double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        if (b == 0) cout << 1 << endl;
        else cout << a/(16*b)+0.5 << endl;
    }
}


#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    long double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        if (b == 0) cout << 1 << endl;
        else cout << ((a/(16*b)) + 0.5)*min(a, 4*b)/a + max(a-4*b, a - a)/a << endl;
    }
}


#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        cout << a/(16*b)+0.5 << endl;
    }
}