#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int main(){
	int n,m;
	cin>>n>>m;
	map<int,int>mm;
	multiset<int>ss;
	for(int i=0;i<m;i++)mm[i]=i;
	for(int i=0;i<m;i++)ss.insert(0);
	for(int i=1,add=1;i<=n;i++){
		int a,b,c,d;
		cin>>a>>b;
		c=-1;
		for(auto j=mm.lower_bound(--a);j!=mm.end()&&j->F<=b;mm.erase(j++)){
			d=j->F;
			c=max(c,mm[d]);
			ss.erase(ss.find(d-mm[d]));
		}
		if(c+1&&b<m)mm[b]=c,ss.insert(b-c);
		if(ss.size())cout<<*ss.begin()+add<<endl,add++;
		else puts("-1");
	}
}
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+2;
int pre1[MAXN],pre2[MAXN];
int finds(int x,int *pre)
{
    return pre[x] == x? pre[x]:pre[x] = finds(pre[x],pre);
}
void join(int x,int y,int *pre)
{
    int px = finds(x,pre);
    int py = finds(y,pre);
    if( px!=py)
    {
        pre[px] = py;
    }
}
int main()
{
    int n,k,l;
    cin>>n>>k>>l;
    for(int i = 1;i<=n;i++)
        pre1[i] = i,pre2[i] = i;
    for(int i = 1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        join(x,y,pre1);
    }
    for(int i = 1;i<=l;i++)
    {
        int x,y;
        cin>>x>>y;
        join(x,y,pre2);
    }
    for(int i = 1;i<=n;i++)
    {
        finds(i,pre1);
        finds(i,pre2);
    }
    map<pair<int,int>,int> mp;
    for(int i = 1;i<=n;i++)
    {
        mp[make_pair(pre1[i],pre2[i])] ++;
    }
    for(int i = 1;i<=n;i++)
    {
        cout<<mp[make_pair(pre1[i],pre2[i])]<<" ";
    }
    cout<<endl;
}