#include<bits/stdc++.h>
using namespace std;
template
class graph{
int v;
map<T,list>m;
public:
graph(int v){
this->v=v;
}
void addedge(int x,int y){
m[x].push_back(y);
// m[y].push_back(x);
}
int bfsshortest(T src,T dest){
map<T,int>dist;
bool visited[v];
for(auto p:m){
dist[p.first]=-1;
visited[p.first]=false;
}
queue<T>q;
q.push(src);
dist[src]=0;
visited[src]=true;
while(!q.empty()){
T node=q.front();
q.pop();
visited[node]=true;
for(auto p:m[node]){
if(!visited[p]){
q.push(p);
dist[p]=dist[node]+1;
visited[p]=true;
}
}
}
return dist[dest];
}
};
int main() {
int t;
cin>>t;
while(t--){
int n,l,s;
cin>>n>>l>>s;
int board[n]={0};
graph<int> g(n);
int p=l+s;
while(p--){
int x,y;
cin>>x>>y;
board[x]=y-x;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=6;j++){
int k=i+j;
k=k+board[k];
g.addedge(i,k);
}
}
cout<<g.bfsshortest(1,n)<<endl;
}
return 0;
}
segmentation fault occurs why