#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <iostream>
#define MAX(a,b) a>b? a:b
using namespace std;
int in[30]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
/*http://acm.hdu.edu.cn/showproblem.php?pid=1230*/
int main()
{
char one[1000], two[100];
int one_seat[50], two_seat[50], three_seat[50];
int one_num, two_num;
memset(one, ' ', sizeof(one) );
memset(two, ' ', sizeof(two) );
while(~scanf("%s%s", one, two) )
{
char *p = one, *q = two;
one_num = two_num = 1;
memset(one_seat, 0, sizeof(one_seat) );
memset(two_seat, 0, sizeof(two_seat) );
memset(three_seat, 0, sizeof(three_seat) );
while(1)
{
while( (*p) == ',') p++;
if( (*p) != ' ')
{
one_seat[one_num++] = atoi(p);
while( (*p) != ',' && (*p) !=' ') {p++; if( (*p) ==' ') break; } p++;
}
else break;
}
while(1)
{
if( (*q) != ' ')
{
two_seat[two_num++] = atoi(q);
while( (*q) != ',' && (*q) != ' ') {q++; if( (*q) ==' ') break; } q++;
}
else break;
}
if(one_seat[1] + two_seat[1] == 0 && one_seat[2]+ two_seat[2] ==0) break;
int carry=0, seat=0;
for(int i= one_num-1, j= two_num-1; i>=0 || j>=0 || carry != 0; i--,j--)
{
if(i <= 0) i=0;
if(j <= 0) j=0;
three_seat[i] = (one_seat[i] + two_seat[j] +carry) % in[seat];
carry = (one_seat[i] + two_seat[j] + carry) / in[seat++];
}
int i=0;
while( three_seat[i] == 0)
i++;
for(; i<seat-1; i++)
printf("%d,", three_seat[i] );
printf("%d
", three_seat[i]);
memset(one, ' ', sizeof(one) );
memset(two, ' ', sizeof(two) );
}
return 0;
}