#include "Intel_Compatibility.h"
#include <map>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Chemical {
	int ID;
	string Name;
	int initValue;
};

int main(int argc, char* argv[])
{
	ifstream inputA(argv[1]);
	ifstream inputB(argv[2]);
	ofstream outputC(argv[3]);
	
	map<string, int> FileA_Values;
	
	int numChemsA = 0, numChemsB = 0;

	inputA >> numChemsA;
	
	for(int i = 0; i < numChemsA; i++) {
		int x = 0, y = 0;
		string name;
		inputA >> x >> name >> y;
		FileA_Values[name] = y;
	}

	vector<Chemical> FileB_Values;
	
	inputB >> numChemsB;

	outputC << numChemsB << std::endl << std::endl;
	
	for(int i = 0; i < numChemsB; i++) {
		Chemical c;
		inputB >> c.ID >> c.Name >> c.initValue;
	
		if(FileA_Values.find(c.Name) != FileA_Values.end())
			c.initValue = FileA_Values[c.Name];

		outputC << c.ID << "	" << c.Name << "	" << c.initValue << std::endl;
	}
	
	return 0;
}
