#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
using namespace std;

const int INF = 1 << 30;
const int maxn = 2 * 100000 + 100;

int book[maxn];
int fa1[maxn];
int fa2[maxn];

int find1x(int x)
{
     if (fa1[x] != x)
     {
          fa1[x] = find1x(fa1[x]);
     }
     return fa1[x];
}

int find2x(int x)
{
     if (fa2[x] != x)
     {
          fa2[x] = find2x(fa2[x]);
     }
     return fa2[x];
}


int main()
{
     int n, k, l;
     int i, j, tmp, x, y;
     int a, b;

     memset(book, 0, sizeof(book));

     scanf("%d%d%d", &n, &k, &l);

     for (i = 0; i <= n; i++)
     {
          fa1[i] = i;
          fa2[i] = i;
     }
     for (i = 0; i < k; i++)
     {
          scanf("%d%d", &a, &b);
          tmp = find1x(b);
          x = a;
          while (fa1[x] != x)
          {
               y = fa1[x];
               fa1[x] = tmp;
               x = y;
          }
          fa1[x] = tmp;
     }
     for (i = 0; i < l; i++)
     {
          scanf("%d%d", &a, &b);
          if (find1x(a) == find1x(b))
          {
               tmp = find2x(b);
               x = a;
               while (fa2[x] != x)
               {
                    y = fa2[x];
                    fa2[x] = tmp;
                    x = y;
               }
               fa2[x] = tmp;
          }
     }


     printf("fa1: ");
     for (i = 1; i <= n; i++)
          printf("%d ", fa1[i]);
     printf("\n");
     printf("fa2: ");
     for (i = 1; i <= n; i++)
          printf("%d ", fa2[i]);
     printf("\n");


     for (i = 1; i <= n; i++)
     {
          book[find2x(i)]++;
     }

     for (i = 1; i <= n; i++)
     {
          printf("%d ", book[find2x(i)]);
     }
     return 0;
}
