human
This is the hard version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved.

A forest is an undirected graph without cycles (not necessarily connected).

Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from 1 to n, and they would like to add edges to their forests such that: 

  * After adding edges, both of their graphs are still forests. 
  * They add the same edges. That is, if an edge (u, v) is added to Mocha's forest, then an edge (u, v) is added to Diana's forest, and vice versa. 


Mocha and Diana want to know the maximum number of edges they can add, and which edges to add.

Input

The first line contains three integers n, m_1 and m_2 (1 ≤ n ≤ 10^5, 0 ≤ m_1, m_2 < n) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest.

Each of the next m_1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Mocha's forest.

Each of the next m_2 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Diana's forest.

Output

The first line contains only one integer h, the maximum number of edges Mocha and Diana can add.

Each of the next h lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edge you add each time.

If there are multiple correct answers, you can print any one of them.

Examples

Input

3 2 2
1 2
2 3
1 2
1 3

Output

0

Input

5 3 2
5 4
2 1
4 3
4 3
1 4

Output

1
2 4

Input

8 1 2
1 7
2 6
1 5

Output

5
5 2
2 3
3 4
4 7
6 8

Note

In the first example, we cannot add any edge.

In the second example, the initial forests are as follows.


We can add an edge (2, 4).

def n Can you provide a Python code to print any one of them?
assistant
#Here is Python code to print any one of them.
aiveSolve():
    
    
    
    return

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
    def find(self, a): #return parent of a. a and b are in same set if they have same parent
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a: #path compression
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a
    def union(self, a, b): #union a and b
        self.parent[self.find(b)] = self.find(a)

def main():
    
    n,m1,m2=readIntArr()
    
    uf1=UnionFind(n+1)
    uf2=UnionFind(n+2)
    
    for _ in range(m1):
        u,v=readIntArr()
        uf1.union(u,v)
    for _ in range(m2):
        u,v=readIntArr()
        uf2.union(u,v)
    
    # eventually 1 of the forests will only have 1 component
    # order of merging does not affect number of edges added
    # try to merge everything to 1 of both forests
    # start by using same nodes where u is not merged to 1 for both forests
    
    ans=[]
    for u in range(1,n+1):
        if uf1.find(1)!=uf1.find(u) and uf2.find(1)!=uf2.find(u):
            ans.append((1,u))
            uf1.union(1,u)
            uf2.union(1,u)
    
    # now, if u is not matched to 1 in forest 1, it must be matched to 1
    # in forest 2. same logic for u not matched to 1 in forest 2.
    # any u1 not matched to 1 in forest 1 can be matched to u2 not matched
    # to 1 in forest 2.
    u1=1
    u2=1
    while True:
        while u1<=n and uf1.find(1)==uf1.find(u1):
            u1+=1
        while u2<=n and uf2.find(1)==uf2.find(u2):
            u2+=1
        if u1<=n and u2<=n:
            ans.append((u1,u2))
            uf1.union(u1,1) # can also union(u1,u2)
            uf2.union(u2,1)
        else:
            break
    print(len(ans))
    multiLineArrayOfArraysPrint(ans)
    
    
    return

import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
# input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT...