#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int c, n, e;
int grid[2][N];
vector<vector<int> > g;
int at;
int parent[N];
void BFS(int u) {
queue<int> q;
memset(parent, -1, sizeof(parent));
q.push(u);
parent[u] = -2;
while (!q.empty()) {
u = q.front();
q.pop();
for (auto &v : g[u])
if (parent[v] == -1) {
parent[v] = u;
q.push(v);
}
}
at = u;
}
int hasOtherCommon(int u, int v, int than) {
set<int> s(g[u].begin(), g[u].end());
s.erase(than);
for (auto &x : g[v])
if (s.find(x) != s.end())
return x;
return -1;
}
vector<pair<int, int> > loc;
void updateColumn(int i, bool flip, int shift) {
if (grid[0][i] != -1) {
loc[grid[0][i]].first ^= flip;
loc[grid[0][i]].second -= shift;
}
if (grid[1][i] != -1) {
loc[grid[1][i]].first ^= flip;
loc[grid[1][i]].second -= shift;
}
}
void print() {
memset(grid, -1, sizeof(grid));
int minCol = n;
for (int i = 0; i < n; ++i)
minCol = min(minCol, loc[i].second);
for (int i = 0; i < n; ++i)
grid[loc[i].first][loc[i].second - minCol] = i;
for (int i = 0; i < 2; ++i, puts(""))
for (int j = 0; j < c; ++j)
printf("%d ", grid[i][j] + 1);
}
int main() {
scanf("%d%d%d", &c, &n, &e);
g.resize(n);
for (int i = 0, a, b; i < e; ++i) {
scanf("%d%d", &a, &b);
--a; --b;
g[a].push_back(b);
g[b].push_back(a);
}
for (auto &v : g) {
sort(v.begin(), v.end(), [&](const int &a, const int &b) {
return g[a].size() < g[b].size();
});
}
BFS(0);
int e1 = at;
BFS(at);
int e2 = at;
vector<int> path;
int cur = e2;
while (cur != -2) {
path.push_back(cur);
cur = parent[cur];
}
reverse(path.begin(), path.end());
loc.resize(n, make_pair(-1, -1));
memset(grid, -1, sizeof(grid));
if (path.size() == n) {
grid[0][0] = path[0];
loc[path[0]] = { 0,0 };
int r = 1, c = 0;
for (int j = 1; j < path.size(); ++j) {
grid[r][c] = path[j];
loc[path[j]] = { r,c };
if (c % 2 == 0 && grid[!r][c] == -1)
r = !r;
else
++c;
}
print();
return 0;
}
loc[path[0]] = { 0,0 };
grid[0][0] = path[0];
int r = 0, c = 1;
for (int i = 1; i + 1 < path.size(); ++i) {
int ret = hasOtherCommon(path[i - 1], path[i + 1], path[i]);
if (ret != -1) {
r = !r;
--c;
}
loc[path[i]] = { r,c };
grid[r][c] = path[i];
++c;
if (ret != -1) {
loc[ret] = { !r,c };
grid[!r][c] = ret;
}
}
loc[path.back()] = { r,c };
grid[r][c] = path.back();
for (int c = 0; c < n; ++c)
for (int r = 0; r < 2; ++r)
if (grid[r][c] != -1) {
if (grid[!r][c] != -1)
continue;
bool found = false;
for (auto &x : g[grid[r][c]])
if (loc[x].first == -1) {
loc[x] = { !r,c };
grid[!r][c] = x;
found = true;
break;
}
if (found)
break;
}
int prefix = -1;
for (int i = 0; i < n; ++i) {
if (grid[0][i] != -1 && grid[1][i] != -1) {
prefix = i - 1;
break;
}
}
int sum = 0;
bool flip = false;
int shift = 0;
int lastIdx;
for (int i = prefix + 1; i < n; ++i) {
updateColumn(i, flip, shift);
if (grid[0][i] == -1 && grid[1][i] == -1)
break;
if (grid[0][i] != -1 && grid[1][i] != -1) {
sum = 0;
continue;
}
++sum;
if (sum == 4) {
++shift;
flip ^= 1;
updateColumn(i, true, 1);
updateColumn(i - 1, true, 1);
sum = 1;
}
if (grid[0][i] != -1)
lastIdx = grid[0][i];
else if (grid[1][i] != -1)
lastIdx = grid[1][i];
}
if (sum >= 3) {
loc[lastIdx].first ^= 1;
--loc[lastIdx].second;
}
sum = 0;
flip = false;
shift = 0;
for (int i = prefix; i >= 0; --i) {
updateColumn(i, flip, shift);
if (grid[0][i] == -1 && grid[1][i] == -1)
break;
if (grid[0][i] != -1 && grid[1][i] != -1) {
sum = 0;
continue;
}
++sum;
if (sum == 4) {
--shift;
flip ^= 1;
updateColumn(i, true, -1);
updateColumn(i + 1, true, -1);
sum = 1;
}
if (grid[0][i] != -1)
lastIdx = grid[0][i];
else if (grid[1][i] != -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