#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e4 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
char s[N], ss[N], t[1010], tt[1010];
int f[N];
string a[N * 10];
int l[N * 10];
map<string, int>mop;
void print(int p)
{
	if (p == 0)return;
	print(p - l[f[p]]);
	cout << a[f[p]] << " ";
}
int main()
{
	while (~scanf("%d", &n))
	{
		mop.clear();
		scanf("%s", s + 1); MC(ss, s);
		scanf("%d", &m);
		for (int i = 1; i <= m; ++i)
		{
			cin >> a[i];
			string t = a[i];
			l[i] = a[i].size();
			for (int j = 0; j < l[i]; ++j)t[j] = tolower(a[i][l[i] - 1 - j]);
			mop[t] = i;
		}
		MS(f, 0); f[0] = -1;
		for (int i = 1; i <= n; ++i)
		{
			int top = min(i, 1000);
			s[i + 1] = 0;
			for (int j = 1; j <= top; ++j)
			{
				if (f[i - j] == 0)continue;
				if (mop.find(s + (i - j + 1)) == mop.end())continue;
				int o = mop[s + (i - j + 1)];
				if (o == 0)continue;
				f[i] = o;
				break;
			}
			s[i + 1] = ss[i + 1];
		}
		print(n);
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

【时间复杂度&&优化】

【数据】

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e4+10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
char s[N], ss[N], t[1010], tt[1010];
int f[N];
string a[N * 10];
int l[N * 10];
map<string, int>mop;
void print(int p)
{
	if (p == 0)return;
	print(p-l[f[p]]);
	cout << a[f[p]] << " ";
}
int main()
{
	while (~scanf("%d", &n))
	{
		mop.clear();
		scanf("%s", s + 1); MC(ss, s);
		scanf("%d", &m);
		for (int i = 1; i <= m; ++i)
		{
			cin >> a[i];
			string t = a[i];
			l[i]= a[i].size();
			for (int j = 0; j < l[i]; ++j)t[j] = tolower(a[i][l[i]-1-j]);
			mop[t] = i;
		}
		MS(f, 0); f[0] = -1;
		for (int i = 1; i <= n; ++i)
		{
			int top = min(i, 1000);
			s[i + 1] = 0;
			for (int j = 1; j <= top; ++j)
			{
				if (f[i - j] == 0)continue;
				int o = mop[s + (i - j + 1)];
				if (o == 0)continue;
				f[i] = o;
				break;
			}
			s[i + 1] = ss[i + 1];
		}
		print(n);
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

【时间复杂度&&优化】

【数据】

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e4 + 10, M = 1e6+10, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
char s[N], t[1010];
int f[N];
string a[N * 10];
int l[N * 10];
map<string, int>mop;
void print(int p)
{
	if (p == 0)return;
	print(p - l[f[p]]);
	cout << a[f[p]] << " ";
}
int b[M][26]; int id;
int o[M];
void ins(char s[],int ord)
{
	int p = 0;
	for (int i = 0; s[i]; ++i)
	{
		int x = s[i] - 'a';
		if (b[p][x] == 0)b[p][x] = ++id;
		p = b[p][x];
	}
	o[p] = ord;
}
int main()
{
	while (~scanf("%d", &n))
	{
		id = 0;
		MS(a, 0);
		MS(o, 0);
		scanf("%s", s + 1);
		scanf("%d", &m);
		for (int i = 1; i <= m; ++i)
		{
			cin >> a[i];
			l[i] = a[i].size();
			for (int j = 0; j < l[i]; ++j)t[j] = tolower(a[i][j]);
			t[l[i]] = 0;
			ins(t, i);
		}
		MS(f, 0); f[0] = -1;
		for (int i = 1; i <= n; ++i)
		{
			int top = min(i, 1000);
			int p = 0;
			for (int j = 0; j < top; ++j)
			{
				int x = s[i - j] - 'a';
				if (b[p][x] == 0)break;
				p = b[p][x];
				if (f[i - j - 1] && o[p])
				{
					f[i] = o[p];
					break;
				}
			}
		}
		print(n);
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】
1，这道题有一个细节一定要再次警醒！
我在查询一个字符串是否在单词中的时候，
第一次用到的是查看mop[字符串]是否为0，
然而这样子必然会把这个查询字符串也添加入map中，导致map膨胀过大，造成MLE或TLE
比赛的时候就是因为这个浪费了15mins与增加了2次罚时。

2，用string存字符串就可以
用一个长字符串分开存多个小字符串的方法自然也是有优化作用的，然而优化程度却并不大。

3，这道题其实我们直接把加密后的字符串反转就可以了。。。

4，字符串哈希可以不用map，而用字典树，就可以减少一个log时间

【题意】
有一个长度为n（1<=n<=1e4）的加密字符串
这个字符串是由一个若干单词穿成的句子，经过以下的规则加密而成的。

1，单词来源于单词库，单词库会告诉你。
这个单词库内会有m（1<=m<=1e5）个单词，
每个单词的长度都不超过1e3，所有单词的总长度不超过1e6.
2，我们先会把所有选出的单词连乘串（同一个单词可以选择多次），两两之间一个空格
3，对于所有的单词做字符串reverse操作（即前后倒置）。
4，去掉所有的空格
5，转化为小写

现在已知加密字符串和单词库。
让你还原加密前的句子。

【类型】
DP SET-MAP

【分析】
我们可以把所有的单词都倒过来，再转化为小写，加入SET-MAP中
然后我们再枚举一个字符串的尾端点，向前拓展，记录最后一个延展的字符串编号。
这样这道题就做完了。

用map的话，时间复杂度可达O( n*1000 *log(n*1000) )
用trie之后，时间复杂度是O(n*1000)

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e4+10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
char s[N], ss[N], t[1010], tt[1010];
int f[N];
string a[N * 10];
int l[N * 10];
map<string, int>mop;
void print(int p)
{
	if (p == 0)return;
	print(p-l[f[p]]);
	cout << a[f[p]] << " ";
}
int main()
{
	while (~scanf("%d", &n))
	{
		mop.clear();
		scanf("%s", s + 1); MC(ss, s);
		scanf("%d", &m);
		for (int i = 1; i <= m; ++i)
		{
			cin >> a[i];
			string t = a[i];
			l[i]= a[i].size();
			for (int j = 0; j < l[i]; ++j)t[j] = tolower(a[i][l[i]-1-j]);
			mop[t] = i;
		}
		MS(f, 0); f[0] = -1;
		for (int i = 1; i <= n; ++i)
		{
			int top = min(i, 1000);
			s[i + 1] = 0;
			for (int j = 1; j <= top; ++j)
			{
				if (f[i - j] == 0)continue;
if(mop.find(s+(i-j+1)==mop.end())continue;
				int o = mop[s + (i - j + 1)];
				if (o == 0)continue;
				f[i] = o;
				break;
			}
			s[i + 1] = ss[i + 1];
		}
		print(n);
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

【时间复杂度&&优化】

【数据】

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e4 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
char s[N], ss[N], t[1010], tt[1010];
int f[N];
string a[N * 10];
int l[N * 10];
map<string, int>mop;
void print(int p)
{
	if (p == 0)return;
	print(p - l[f[p]]);
	cout << a[f[p]] << " ";
}
int main()
{
	while (~scanf("%d", &n))
	{
		mop.clear();
		scanf("%s", s + 1); MC(ss, s);
		scanf("%d", &m);
		for (int i = 1; i <= m; ++i)
		{
			cin >> a[i];
			l[i] = a[i].size();
			string t;
			for (int j = 0; j < l[i]; ++j)t += tolower(a[i][l[i] - 1 - j]);
			mop[t] = i;
		}
		MS(f, 0); f[0] = -1;
		for (int i = 1; i <= n; ++i)
		{
			int top = min(i, 1000);
			s[i + 1] = 0;
			for (int j = 1; j <= top; ++j)
			{
				if (f[i - j] == 0)continue;
				if (mop.find(s + (i - j + 1)) == mop.end())continue;
				int o = mop[s + (i - j + 1)];
				f[i] = o;
				break;
			}
			s[i + 1] = ss[i + 1];
		}
		print(n);
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

【时间复杂度&&优化】

【数据】

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e4+10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m;
char s[N], ss[N];
int f[N];
char w[N * 110];
int p[N * 10];
int l[N * 10];
char t[1010];
map<string, int>mop;
void print(int pos)
{
	if (pos == 0)return;
	int o = f[pos];
	print(pos - l[o]);
	printf("%s ", w+p[o]);
}
int main()
{
	while (~scanf("%d", &n))
	{
		MS(w, 0);
		mop.clear();
		scanf("%s", s + 1); MC(ss, s);
		scanf("%d", &m);
		p[0] = 0;
		for (int i = 1; i <= m; ++i)
		{
			scanf("%s", w + p[i]);
			l[i]= strlen(w + p[i]);
			p[i + 1] = p[i] + l[i] + 1;

			strcpy(t, w + p[i]); t[l[i]] = 0;
			for (int j = 0; j < l[i]; ++j)t[j] = tolower(t[j]);
			for (int j = 0; j < l[i] / 2;++j)swap(t[j],t[l[i] - 1 - j]);
			mop[t] = i;
		}
		MS(f, 0); f[0] = -1;
		for (int i = 1; i <= n; ++i)
		{
			int top = min(i, 1000);
			s[i + 1] = 0;
			for (int j = 1; j <= top; ++j)
			{
				if (f[i - j] == 0)continue;
				if (mop.find(s + (i - j + 1)) == mop.end())continue;
				int o = mop[s + (i - j + 1)];
				if (o == 0)continue;
				f[i] = o;
				break;
			}
			s[i + 1] = ss[i + 1];
		}
		print(n);
		puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

【时间复杂度&&优化】

【数据】

*/


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

const int maxC = 'z' - 'a' + 1;

struct Node {
    int next[maxC];
    int id;
    Node() {
        memset(this, 0, sizeof(*this));
    }
};

struct Trie {
    vector<Node> T;
    Trie() {
        T.push_back(Node());
        T.reserve(400000);
    }
    void addStr(string s, int id) {
        int v = 0;
        for (auto c : s) {
            c -= 'a';
            if (!T[v].next[c]) {
                T[v].next[c] = T.size();
                T.push_back(Node());
            }
            v = T[v].next[c];
        }
        T[v].id = id;
    }
    vector< int > go(string t) {
        vector< int > ans;
        int v = 0;
        int n = t.size();
        t.push_back('z' + 1);
        for (int i = 0; i <= n; i++) {
            char c = t[i] - 'a';
            if (i == n || T[v].next[c] == 0) {
                if (v == 0) {
                    return vector < int >();
                }
                ans.push_back(T[v].id);
                v = 0;
            }
            if (i < n) {
                v = T[v].next[c];
            }
        }
        return ans;
    }
}tt;

ll n, m;
string a;
string b[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        string s = b[i];
        reverse(s.begin(), s.end());
        for(auto &j : s)
            j = tolower(j);
        tt.addStr(s, i);
    }
    vector < int > anss = tt.go(a);
    assert(!anss.empty());
    for(int i = 0; i < (int)anss.size(); ++i){
        cout << b[anss[i]] << " ";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)9e5];

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i))
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

vector < node > st;

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i)){
            st.pb(node());
            st[v].nxt[i] = sz++;
        }
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    st.pb(node());
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= max(0, i - 1000); --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                if((!j ? 1 : dp[j - 1]) && st[v].id)
                    pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

vector < node > st;

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i)){
            st.pb(node());
            st[v].nxt[i] = sz++;
        }
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    st.pb(node());
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                if((!j ? 1 : dp[j - 1]) && st[v].id)
                    pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

const int maxC = 'z' - 'a' + 1;

struct Node {
    int next[maxC];
    int id;
    Node() {
        memset(this, 0, sizeof(*this));
    }
};

struct Trie {
    vector<Node> T;
    Trie() {
        T.push_back(Node());
        T.reserve(400000);
    }
    void addStr(string s, int id) {
        int v = 0;
        for (auto c : s) {
            c -= 'a';
            if (!T[v].next[c]) {
                T[v].next[c] = T.size();
                T.push_back(Node());
                T.back().id = id;
            }
            v = T[v].next[c];
        }
    }
    vector< int > go(string t) {
        vector< int > ans;
        int v = 0;
        int n = t.size();
        t.push_back('z' + 1);
        for (int i = 0; i <= n; i++) {
            char c = t[i] - 'a';
            if (i == n || T[v].next[c] == 0) {
                if (v == 0) {
                    return vector < int >();
                }
                ans.push_back(T[v].id);
                v = 0;
            }
            if (i < n) {
                v = T[v].next[c];
            }
        }
        return ans;
    }
}tt;

ll n, m;
string a;
string b[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        string s = b[i];
        reverse(s.begin(), s.end());
        for(auto &j : s)
            j = tolower(j);
        tt.addStr(s, i);
    }
    vector < int > anss = tt.go(a);
    for(int i = 0; i < (int)anss.size(); ++i){
        cout << b[anss[i]] << " ";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)1e6];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i))
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
ll n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    ll nxt[27], id;
    ll leaf;
    node(){
        for(ll i = 0; i < 27; ++i) nxt[i] = -1;
        leaf = 0;
    }
    ~node(){}
};

node st[lmaxn];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i -= 'a';
        if(st[v].nxt[i] == -1)
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
ll n, m, dp[lmaxn], pre[lmaxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(st[v].nxt[a[j] - 'a'] == -1)
                break;
            v = st[v].nxt[a[j] - 'a'];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

vector < node > st;

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i)){
            st.pb(node());
            st[v].nxt[i] = sz++;
        }
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    st.pb(node());
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

vector < node > st;

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i)){
            st.pb(node());
            st[v].nxt[i] = sz++;
        }
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    st.pb(node());
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                if(st[v].id)
                    pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

const int maxC = 'z' - 'a' + 1;

struct Node {
    int next[maxC];
    int id;
    Node() {
        memset(this, 0, sizeof(*this));
    }
};

struct Trie {
    vector<Node> T;
    Trie() {
        T.push_back(Node());
        T.reserve(2100 * 2100);
    }
    void addStr(string s, int id) {
        int v = 0;
        for (auto c : s) {
            c -= 'a';
            if (!T[v].next[c]) {
                T[v].next[c] = T.size();
                T.push_back(Node());
                T.back().id = id;
            }
            v = T[v].next[c];
        }
    }
    vector< int > go(string t) {
        vector< int > ans;
        int v = 0;
        int n = t.size();
        t.push_back('z' + 1);
        for (int i = 0; i <= n; i++) {
            char c = t[i] - 'a';
            if (i == n || T[v].next[c] == 0) {
                if (v == 0) {
                    return vector < int >();
                }
                ans.push_back(T[v].id);
                v = 0;
            }
            if (i < n) {
                v = T[v].next[c];
            }
        }
        return ans;
    }
}tt;

ll n, m;
string a;
string b[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        string s = b[i];
        reverse(s.begin(), s.end());
        for(auto &j : s)
            j = tolower(j);
        tt.addStr(s, i);
    }
    vector < int > anss = tt.go(a);
    for(int i = 0; i < (int)anss.size(); ++i){
        cout << b[anss[i]] << " ";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

vector < node > st;

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i)){
            st.pb(node());
            st[v].nxt[i] = sz++;
        }
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    st.pb(node());
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                if(st[v].id)
                    pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind > 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    ll nxt[27], id;
    ll leaf;
    node(){
        for(ll i = 0; i < 27; ++i) nxt[i] = -1;
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)1e6];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i -= 'a';
        if(st[v].nxt[i] == -1)
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
ll n, m, dp[lmaxn], pre[lmaxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(st[v].nxt[a[j] - 'a'] == -1)
                break;
            v = st[v].nxt[a[j] - 'a'];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    ll nxt[27], id;
    ll leaf;
    node(){
        for(ll i = 0; i < 27; ++i) nxt[i] = -1;
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)7e5];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i -= 'a';
        if(st[v].nxt[i] == -1)
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
ll n, m, dp[lmaxn], pre[lmaxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(st[v].nxt[a[j] - 'a'] == -1)
                break;
            v = st[v].nxt[a[j] - 'a'];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
        id = 0;
    }
    ~node(){}
};

vector < node > st;

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i)){
            st.pb(node());
            st[v].nxt[i] = (int)st.size() - 1;
        }
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

ll Go(string f){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i = st[v].nxt[i];
    }
    return st[v].id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    st.pb(node());
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            int len = (i - j + 1);
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                if((!j ? 1 : dp[j - 1]))
                    pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)5e9];

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i))
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

ll n, ans;
ll a[maxn];
map < ll, ll > cnt;

main(){
    scanf("%lld", &n);
    if(n == 1){
        printf("1");
        return 0;
    }
    for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]), ++cnt[a[i]];
    ans = max(ans, cnt[0]);
    sort(a + 1, a + 1 + n);
    for(ll i = 1; i <= n; ++i){
        for(ll j = 1; j <= n; ++j){
            if(i == j) continue;
            if(!a[i] && !a[j]) continue;
            if(a[i] + a[j] < 0){
                ll cnt = 2;
                int lf = i - 1;
                ll p1 = a[i], p2 = a[j];
                while(lf){
                    while(lf > 0 && a[lf] != p1 + p2)
                        --lf;
                    if(lf && a[lf] == a[i] + a[j]){
                        p1 = p2;
                        p2 = a[lf];
                        ++cnt, --lf;
                    }
                }
                ans = max(ans, cnt);
            }
            else{
                ll cnt = 2, p1 = a[i], p2 = a[j];
                ll rg = 1;
                while(rg <= n){
                    while(rg <= n && (a[rg] != p1 + p2 || rg == i || rg == j))
                        ++rg;
                    if(rg <= n && a[rg] == p1 + p2){
                        p1 = p2;
                        p2 = a[rg];
                        ++cnt, ++rg;
                    }
                }
                ans = max(ans, cnt);
            }
        }
    }
    printf("%lld", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int A[1000];
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<string>p;
    int m;
    cin>>m;
    string d[m+1];
    for(int i=0;i<m;i++)
    {
        cin>>d[i];
    }
    for(int i=0;i<s.size();i++)
    {
        A[s[i]-'0']++;
    }
    for(int i=0;i<m;i++)
    {
        int c=0;
        for(int j=0;j<d[i].size();j++)
        {
            if(A[d[i][j]-'0']==0)
            {
                c=1;
                break;
            }
        }
        if(c==0)
        {
            for(int j=0;j<d[i].size();j++)
            {
                A[d[i][j]-'0']--;
            }
            p.push_back(d[i]);
        }
    }
    for(int i=0;i<p.size();i++)
    {
        cout<<p[i];
        if(i!=p[i].size()-1)
        {
            cout<<" ";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    int nxt[27], id;
    int leaf;
    node(){
        for(ll i = 0; i < 27; ++i) nxt[i] = -1;
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)1e6];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i -= 'a';
        if(st[v].nxt[i] == -1)
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(st[v].nxt[a[j] - 'a'] == -1)
                break;
            v = st[v].nxt[a[j] - 'a'];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    map < char, int > nxt;
    int id;
    int leaf;
    node(){
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)1e6];

int sz;

void Add(string f, int id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        if(!st[v].nxt.count(i))
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
int n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(int i = 0; i < n; ++i){
        int v = 0;
        for(int j = i; j >= 0; --j){
            if(!st[v].nxt.count(a[j]))
                break;
            v = st[v].nxt[a[j]];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    int ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

const int maxC = 'z' - 'a' + 1;

struct Node {
    int next[maxC];
    int id;
    Node() {
        memset(this, 0, sizeof(*this));
    }
};

struct Trie {
    vector<Node> T;
    Trie() {
        T.push_back(Node());
        T.reserve(400000);
    }
    void addStr(string s, int id) {
        int v = 0;
        for (auto c : s) {
            c -= 'a';
            if (!T[v].next[c]) {
                T[v].next[c] = T.size();
                T.push_back(Node());
            }
            v = T[v].next[c];
        }
        T[v].id = id;
    }
    vector< int > go(string t) {
        vector< int > ans;
        int v = 0;
        int n = t.size();
        t.push_back('z' + 1);
        for (int i = 0; i <= n; i++) {
            char c = t[i] - 'a';
            if (i == n || T[v].next[c] == 0) {
                if (v == 0) {
                    return vector < int >();
                }
                ans.push_back(T[v].id);
                v = 0;
            }
            if (i < n) {
                v = T[v].next[c];
            }
        }
        return ans;
    }
}tt;

ll n, m;
string a;
string b[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> a >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        string s = b[i];
        reverse(s.begin(), s.end());
        for(auto &j : s)
            j = tolower(j);
        tt.addStr(s, i);
    }
    vector < int > anss = tt.go(a);
    for(int i = 0; i < (int)anss.size(); ++i){
        cout << b[anss[i]] << " ";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    ll nxt[27], id;
    ll leaf;
    node(){
        for(ll i = 0; i < 27; ++i) nxt[i] = -1;
        leaf = 0;
    }
    ~node(){}
};

node st[(ll)5e5];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i -= 'a';
        if(st[v].nxt[i] == -1)
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
ll n, m, dp[lmaxn], pre[lmaxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(st[v].nxt[a[j] - 'a'] == -1)
                break;
            v = st[v].nxt[a[j] - 'a'];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <climits>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <utility>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <deque>

using namespace std;

#if __cplusplus >= 201103
    #include <unordered_map>
    #include <future>
    #include <atomic>
    #include <chrono>
    #include <unordered_set>
    #include <array>
    #include <random>
    #include <mutex>
#endif

#define pii pair<int, int>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define f first
#define s second

typedef long long ll;
typedef long double ld;

const int inf = (int)1e9 + 7;
const int linf = (int)1e16 + 7;
const int maxn = (int)2e5 + 7;
const int lmaxn = (int)1e6 + 7;

const ld eps = ld(1e-11);

struct node{
    ll nxt[27], id;
    ll leaf;
    node(){
        for(ll i = 0; i < 27; ++i) nxt[i] = -1;
        leaf = 0;
    }
    ~node(){}
};

node st[maxn];

ll sz;

void Add(string f, ll id){
    ll v = 0;
    for(char i : f){
        i = tolower(i);
        i -= 'a';
        if(st[v].nxt[i] == -1)
            st[v].nxt[i] = ++sz;
        v = st[v].nxt[i];
    }
    st[v].leaf = true;
    st[v].id = id;
}

string a, b[maxn];
vector < string > ans;
ll n, m, dp[maxn], pre[maxn];

main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> a >> m;
    for(ll i = 1; i <= m; ++i){
        cin >> b[i];
        Add(b[i], i);
    }
    for(ll i = 0; i < n; ++i){
        ll v = 0;
        for(ll j = i; j >= 0; --j){
            if(st[v].nxt[a[j] - 'a'] == -1)
                break;
            v = st[v].nxt[a[j] - 'a'];
            if(st[v].leaf){
                dp[i] |= (!j ? 1 : dp[j - 1]);
                pre[i] = st[v].id;
            }
        }
    }
    assert(dp[n - 1]);
    ll ind = n - 1;
    while(ind >= 0){
        ans.pb(b[pre[ind]]);
        ind -= (ll)b[pre[ind]].size();
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int t , n , x , d , h;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxd1 = -1e9 - 7 , mxd = -1e9 - 7;
		for(int j = 0; j < n; j++ ) {
			cin >> d >> h;
			mxd1 = max(mxd1 , d);
			mxd = max(mxd , (d - h));
		}
		x -= mxd1;
		long long res = 1;
		if(x > 0) {
			if(mxd <= 0) res = -1;
			else res += (x + mxd1 - 1) / mxd1;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int d[105] , h[105];
int main() {
	int t , n , x;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxdh = -2e9;
		for(int j = 0; j < n; j++ ) {
			cin >> d[i] >> h[i];
			mxdh = max(mxdh , (d[i] - h[i]));
		}
		mxd = *max_element(d , d + n);
		x -= mxd;
		long long res = 1;
		if(x > 0) {
			if(mxd <= 0) res = -1;
			else res += (x + mxdh - 1) / mxdh;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int d[105] , h[105];
int main() {
	int t , n , x;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxdh = -2e9;
		for(int j = 0; j < n; j++ ) {
			cin >> d[i] >> h[i];
			mxdh = max(mxdh , (d[i] - h[i]));
		}
		int mxd = *max_element(d , d + n);
		x -= mxd;
		long long res = 1;
		if(x > 0) {
			if(mxd <= 0) res = -1;
			else res += (x + mxdh - 1) / mxdh;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int t , n , x , d , h;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxd1 = -2e9 , mxd = -2e9;
		for(int j = 0; j < n; j++ ) {
			cin >> d >> h;
			mxd1 = max(mxd1 , d);
			mxd = max(mxd , (d - h));
		}
		x -= mxd1;
		long long res = 1;
		if(x > 0) {
			if(mxd <= 0) res = -1;
			else res += (x + mxd1 - 1) / mxd1;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int d[105] , h[105];
int main() {
	int t , n , x;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxdh = -2e9;
		for(int j = 0; j < n; j++ ) {
			cin >> d[j] >> h[j];
			mxdh = max(mxdh , (d[j] - h[j]));
		}
		int mxd = *max_element(d , d + n);
		x -= mxd;
		long long res = 0;
		if(x > 0) {
			if(mxdh <= 0) res = -1;
			else res += (x + mxdh - 1) / mxdh;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int t , n , x , d , h;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxd1 = -2e9 , mxd = -2e9;
		for(int j = 0; j < n; j++ ) {
			cin >> d >> h;
			mxd1 = max(mxd1 , d);
			mxd = max(mxd , (d - h));
		}
		x -= mxd;
		long long res = 1;
		if(x > 0) {
			if(mxd <= 0) res = -1;
			else res += (x + mxd1 - 1) / mxd1;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int t , n , x , d , h;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxd1 = -1e9 - 7 , mxd = -1e9 - 7;
		for(int j = 0; j < n; j++ )
			cin >> d >> h , mxd1 = max(mxd1 , d) , mxd = max(mxd , (d - h));
		x -= mxd1;
		int res = 1;
		if(x > 0) {
			if(mxd <= 0) res = -1;
			else res += (x + mxd1 - 1) / mxd1;
		}
		cout << res << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int d[105] , h[105];
int main() {
	int t , n , x;
	cin >> t;
	for(int i = 0; i < t; i++ ) {
		cin >> n >> x;
		int mxdh = -2e9;
		for(int j = 0; j < n; j++ ) {
			cin >> d[j] >> h[j];
			mxdh = max(mxdh , (d[j] - h[j]));
		}
		int mxd = *max_element(d , d + n);
		x -= mxd;
		long long res = 1;
		if(x > 0) {
			if(mxdh <= 0) res = -1;
			else res += (x + mxdh - 1) / mxdh;
		}
		cout << res << '\n';
	}
	return 0;
}


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

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        int cnt = 1;
        x-=max_dmg;
        if (x > 0){
            if (best_diff < 1) cout << "-1\n";
            else cnt += (x+best_diff-1)/best_diff;
        }
        cout << cnt << endl;
    return 0;
    }
}


#include <iostream>

using namespace std;

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        if (best_diff < 1) cout << "-1\n";
        else{
            int cnt = 0;
            while(x > 0){
                cnt++;
                if (x <= max_dmg){
                    break;
                    }
                x -= best_diff;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = INT_MIN;
        //vector<pair<int,int>> v;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            if (d > max_dmg) max_dmg = d;
            if (d - h > best_diff) best_diff = d - h;
        }
        if (best_diff < 1) cout << "-1\n";
        else{
            int cnt = 0;
            while(x > 0){
                if (x < max_dmg){
                    cnt++;
                    break;
                    }
                x -= best_diff;
                cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


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

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        int cnt = 1;
        x-=max_dmg;
        if (x > 0){
            if (best_diff < 1) cout << "-1\n";
            else res += (x+best_diff-1)/best_diff;
        }
        cout << res << endl;
    return 0;
}


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

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        int cnt = 1;
        x-=max_dmg;
        if (x > 0){
            if (best_diff < 1) cout << "-1\n";
            else {
                cnt += (x+best_diff-1)/best_diff;
                cout << cnt << endl;
            }
        }
        else cout<<cnt << endl;
    }
    return 0;
    }


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

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        int cnt = 1;
        x-=max_dmg;
        if (x > 0){
            if (best_diff < 1) cout << "-1\n";
            else {
                cnt += (x+best_diff-1)/best_diff;
                cout << cnt << endl;
            }
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            if (d > max_dmg) max_dmg = d;
            if (d - h > best_diff) best_diff = d - h;
        }
        if (best_diff < 1) cout << "-1\n";
        else{
            int cnt = 0;
            while(x > 0){
                if (x <= max_dmg){
                    cnt++;
                    break;
                    }
                x -= best_diff;
                cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


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

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        int cnt = 1;
        x-=max_dmg;
        if (x > 0){
            if (best_diff < 1) cout << "-1\n";
            else cnt += (x+best_diff-1)/best_diff;
        }
        cout << cnt << endl;
    }
    return 0;
}


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

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = -2e9;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            max_dmg = max(d,max_dmg);
            best_diff = max(best_diff,d - h);
        }
        int cnt = 1;
        x-=max_dmg;
        if (x > 0){
            if (best_diff < 1) cout << "-1\n";
            else res += ((x+best_diff-1)/best_diff);
        }
        cout << res << endl;

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i){
        int n, x;
        cin >> n >> x;
        int max_dmg = 1;
        int best_diff = INT_MIN;
        //vector<pair<int,int>> v;
        for (int i = 0; i < n; ++i){
            int d,h;
            cin >> d >> h;
            if (d > max_dmg) max_dmg = d;
            if (d - h > best_diff) best_diff = d - h;
        }
        if (best_diff < 1) cout << "0\n";
        else{
            int cnt = 0;
            while(x > 0){
                if (x < max_dmg){
                    cnt++;
                    break;
                    }
                x -= best_diff;
                cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double
#define endl "\n"

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

#define ull unsigned long long

void solve() {
    ll n, x;
    cin >> n >> x;

    vector<ll> d(n), h(n);
    bool good = false;
    ll max_diff = 0;
    ll mx_d = 0;
    for(int i = 0; i < n; i++) {
        cin >> d[i] >> h[i];
        if(d[i] > h[i]) {
            good = true;
            if(d[i] - h[i] > max_diff) {
                max_diff = d[i] - h[i];
            }
            mx_d = max(mx_d, d[i]);
        }
    }

    if(!good) {
        cout << -1 << endl;
    }
    else {
        ll l = 0, r = x + 1;
        ll ans;
        while(l < r) {
            ll mid = (l + r) / 2;

            if(x - mid * max_diff <= mx_d) {
                //              l = mid + 1;
                r = mid;
                if(x - mid * max_diff <= 0) {
                    ans = mid;
                }
                else {
                    ans = mid + 1;
                }
            }
            else {
                //              r = mid;
                l = mid + 1;
            }
        }

        cout << ans << endl;
        //        for(int i = max(0LL, min(r, l) - 10); i <= min(l, r) + 10; i++) {
        //            if(x - max_diff * (ll)i <= d[max_pos]) {
        //                cout << i + 1 << endl;
        //                return;
        //            }
        //        }

        //        assert(false);
        //        int p = -1;
        //        for(int step = x; step >= 1; step /= 2) {
        //            while((p + step) * max_diff < x) p += step;
        //        }

        //        cout << p << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double
#define endl "\n"

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

#define ull unsigned long long

void solve() {
    int n, x;
    cin >> n >> x;

    vector<int> d(n), h(n);
    bool good = false;
    ll max_diff = 0;
    int max_pos = -1;
    for(int i = 0; i < n; i++) {
        cin >> d[i] >> h[i];
        if(d[i] > h[i]) {
            good = true;
            if(d[i] - h[i] > max_diff) {
                max_diff = d[i] - h[i];
                max_pos = i;
            }
        }
    }

    if(!good) {
        cout << -1 << endl;
    }
    else {
        ll l = 0, r = x + 1;
        while(l < r) {
          ll mid = (l + r) / 2;

          if(mid * max_diff < x) {
              l = mid + 1;
          }
          else {
              r = mid;
          }
        }

        for(int i = max(0LL, r - 10); i <= r + 10; i++) {
            if(x - max_diff * i <= d[max_pos]) {
                cout << i + 1 << endl;
                return;
            }
        }

        assert(false);
//        int p = -1;
//        for(int step = x; step >= 1; step /= 2) {
//            while((p + step) * max_diff < x) p += step;
//        }

//        cout << p << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double
#define endl "\n"

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

#define ull unsigned long long

void solve() {
    int n, x;
    cin >> n >> x;

    vector<int> d(n), h(n);
    bool good = false;
    ll max_diff = 0;
    int max_pos = -1;
    for(int i = 0; i < n; i++) {
        cin >> d[i] >> h[i];
        if(d[i] > h[i]) {
            good = true;
            if(d[i] - h[i] > max_diff) {
                max_diff = d[i] - h[i];
                max_pos = i;
            }
        }
    }

    if(!good) {
        cout << -1 << endl;
    }
    else {
        ll l = 0, r = x + 1;
        while(l < r) {
          ll mid = (l + r) / 2;

          if(mid * max_diff < x) {
              l = mid + 1;
          }
          else {
              r = mid;
          }
        }

        for(int i = max(0LL, min(r, l) - 10); i <= min(l, r) + 10; i++) {
            if(x - max_diff * i <= d[max_pos]) {
                cout << i + 1 << endl;
                return;
            }
        }

        assert(false);
//        int p = -1;
//        for(int step = x; step >= 1; step /= 2) {
//            while((p + step) * max_diff < x) p += step;
//        }

//        cout << p << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double
#define endl "\n"

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

#define ull unsigned long long

void solve() {
    ll n, x;
    cin >> n >> x;

    vector<ll> d(n), h(n);
    bool good = false;
    ll max_diff = 0;
    ll mx_d = 0;
    for(int i = 0; i < n; i++) {
        cin >> d[i] >> h[i];
        if(d[i] > h[i]) {
            good = true;
            if(d[i] - h[i] > max_diff) {
                max_diff = d[i] - h[i];
            }

        }
        mx_d = max(mx_d, d[i]);
    }

    if(!good) {
        cout << -1 << endl;
    }
    else {
        ll l = 0, r = x + 1;
        ll ans;
        while(l < r) {
            ll mid = (l + r) / 2;

            if(x - mid * max_diff <= mx_d) {
                r = mid;
                if(x - mid * max_diff <= 0) {
                    ans = mid;
                }
                else {
                    ans = mid + 1;
                }
            }
            else {
                l = mid + 1;
            }
        }

        cout << ans << endl;
        //        for(int i = max(0LL, min(r, l) - 10); i <= min(l, r) + 10; i++) {
        //            if(x - max_diff * (ll)i <= d[max_pos]) {
        //                cout << i + 1 << endl;
        //                return;
        //            }
        //        }

        //        assert(false);
        //        int p = -1;
        //        for(int step = x; step >= 1; step /= 2) {
        //            while((p + step) * max_diff < x) p += step;
        //        }

        //        cout << p << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double
#define endl "\n"

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

#define ull unsigned long long

void solve() {
    ll n, x;
    cin >> n >> x;

    vector<ll> d(n), h(n);
    bool good = false;
    ll max_diff = 0;
    int max_pos = -1;
    for(int i = 0; i < n; i++) {
        cin >> d[i] >> h[i];
        if(d[i] > h[i]) {
            good = true;
            if(d[i] - h[i] > max_diff) {
                max_diff = d[i] - h[i];
                max_pos = i;
            }
        }
    }

    if(!good) {
        cout << -1 << endl;
    }
    else {
        ll l = 0, r = x + 1;
        while(l < r) {
          ll mid = (l + r) / 2;

          if(mid * max_diff + d[max_pos] < x) {
              l = mid + 1;
          }
          else {
              r = mid;
          }
        }

        for(int i = max(0LL, min(r, l) - 10); i <= min(l, r) + 10; i++) {
            if(x - max_diff * (ll)i <= d[max_pos]) {
                cout << i + 1 << endl;
                return;
            }
        }

        assert(false);
//        int p = -1;
//        for(int step = x; step >= 1; step /= 2) {
//            while((p + step) * max_diff < x) p += step;
//        }

//        cout << p << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}