#include <iostream>
#include <map>
#include <algorithm>
#define N 210
using namespace std;

int n, m;
int d[N][N];

bool check(){
	for (int k = 0; k < m; k++){
		for (int i = 0; i < m; i++){
			for (int j = 0; j < m; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	for (int i = 0; i < m; i++){
		if (d[i][i] < 0){
			return false;
		}
	}
	return true;
}

int main(){
	string a, b, s;
	int x;
	char c;

	while (cin >> n && n){
		m = n * 2;
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N; j++){
				d[i][j] = 100000000;
			}
			d[i][i] = 0;
		}
		map<string, int> units;
		m = 0;
		for (int i = 0; i < n; i++){
			cin >> x >> a >> c;
			cin >> x >> c;
			cin >> x >> b;

			if (units.find(a) == units.end()){
				units[a] = m++;
			}
			if (units.find(b) == units.end()){
				units[b] = m++;
			}

			int an = units[a], bn = units[b];

			d[an][bn] = -x;
			d[bn][an] = x;
		}

		if (check()){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl; 
		}
	}
	return 0;
}