#include <iostream>
#include <string>
#include <sstream>
using namespace std;

#define SAFE_DELETE( x ) { if ( x ){ delete x; x = NULL; } }

struct tCell{
	tCell() : num( 0 ), times( 0 ), prev( NULL ), next( NULL ){}

	int num, times;
	tCell *prev, *next;
};

class MyArray{
public:
	MyArray() : mSize( 0 ), head( NULL ), tail( NULL ){
		head = new tCell;
		tail = new tCell;
		head->next = tail;
		tail->prev = head;
	}
	~MyArray(){
		init();
		SAFE_DELETE( tail );
		SAFE_DELETE( head );
	}

	void init(){
		for ( int i = mSize; i > 0; --i ){
			tCell* cell = tail->prev;
			cell->prev->next = cell->next;
			cell->next->prev = cell->prev;
			SAFE_DELETE( cell );
		}
		mSize = 0;
	}
	void store( int n, int t = 0 ){
		tCell* cell = head;
		int index = find( n );
		if ( index ){
			for ( int i = 0; i < index; ++i ){
				cell = cell->next;
			}
			++cell->times;
		}else{
			tCell* cell = new tCell;
			cell->num = n;
			if ( t ) cell->times = t;
			else ++cell->times;
			cell->prev = tail->prev;
			cell->next = tail;
			cell->prev->next = cell;
			cell->next->prev = cell;
			++mSize;
		}
	}
	int find( int ref ){
		tCell* cell = head;
		for ( int i = 0; i < mSize; ++i ){
			cell = cell->next;
			if ( cell->num == ref ){
				return i+1;
			}
		}
		return 0;
	}
	void comp( MyArray& a1, MyArray& a2 ){
		init();
		for ( int i = 0; i < a1.size(); ++i ){
			for ( int j = 0; j < a2.size(); ++j ){
				if ( a1[ i ].num == a2[ j ].num ){
					store( a1[ i ].num, a1[ i ].times+a2[ j ].times );
				}
			}
		}
		for ( int i = 0; i < mSize-1; ++i ){
			tCell* cell = head;
			for ( int j = 0; j < mSize-1-i; ++j ){
				cell = cell->next;
				if ( cell->num > cell->next->num ){
					tCell* prev = cell->prev;
					tCell* next = cell->next;
					tCell* nNext = cell->next->next;
					prev->next = next;
					cell->prev = next;
					cell->next = nNext;
					next->prev = prev;
					next->next = cell;
					nNext->prev = cell;
					cell = cell->prev;
				}
			}
		}
	}
	int size(){ return mSize; }

	tCell operator[]( int index ){
		tCell* cell = head->next;
		for ( int i = 0; i < index; ++i ){
			cell = cell->next;
		}
		return *cell;
	}

private:
	int mSize;
	tCell *head, *tail;
};

int main(){
	int num, day;
	char c;
	string s;
	MyArray list1, list2, result;

	while ( getline( cin, s ) && s.size() ){
		istringstream iss( s );
		iss >> num >> c >> day;
		list1.store( num );
	}

	while ( getline( cin, s ) && s.size() ){
		istringstream iss( s );
		iss >> num >> c >> day;
		list2.store( num );
	}

	result.comp( list1, list2 );

	for ( int i = 0; i < result.size(); ++i ){
		cout << result[ i ].num << " " << result[ i ].times << endl;
	}

	return 0;
}