
#include <stdio.h>
#include <stdlib.h>
typedef struct QNode
{
char data;
struct QNode* next;
}QNode;
void enQ(QNode* pQ, int e)
{
QNode* pR, * pT;
pR = pQ;
while (pR->next != NULL)
pR = pR->next;
pT = (QNode*)malloc(sizeof(QNode));
pT->next = NULL;
pT->data = e;
pR->next = pT;
pR = pT;
}
void enQueue(QNode* pQ, int n)
{
char x;
QNode* pR, *pT;
pR = pQ;
while (1)
{
scanf("%c", &x);
if (x == '\n')
break;
if (x == ' ')
continue;
else
{
pT = (QNode*)malloc(sizeof(QNode));
pT->next = NULL;
pT->data = x;
pR->next = pT;
pR = pT;
}
}
}
char gethead(QNode* pQ)
{
if (pQ->next == NULL)
return 0;
int e;
QNode* pR;
pR = pQ->next;
e = pR->data;
pQ->next = pR->next;
free(pR);
return e;
}
void opQueue(QNode* pM, QNode* pF)
{
int n, i = 0;
char m, f;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
m = gethead(pM);
enQ(pM, m);
f = gethead(pF);
enQ(pF, f);
}
printf("%c %c", m, f);
}
int main()
{
int m, f, n;
QNode* pM, * pF;
pM = (QNode*)malloc(sizeof(QNode));
pM->next = NULL;
pF = (QNode*)malloc(sizeof(QNode));
pF->next = NULL;
scanf("%d", &m);
getchar();
enQueue(pM, m);
scanf("%d", &f);
getchar();
enQueue(pF, f);
opQueue(pM, pF);
return 0;
}