#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int loc;
};

int N;
char name_table[200][17];
char left_table[100][17],relative[100][17],right_table[100][17];

bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

Info info[200];
bool used[100];

int get_relative(char buf[17]){

	int ret = 0;

	if(buf[3] == '-'){
		for(int i = 4; buf[i] != '\0'; i++){
			ret = 10*ret+buf[i]-'0';
		}
		ret*= -1;
	}else{
		for(int i = 3; buf[i] != '\0'; i++){
			ret = 10*ret+buf[i]-'0';
		}
	}
	return ret;
}

void func(){

	for(int i = 0; i < 100; i++){
		info[i].loc = -1;
		used[i] = false;
	}

	int tmp;
	char buf[2];

	for(int i = 0; i < N; i++){
		scanf("%d %s %s %s %s",&tmp,left_table[i],buf,relative[i],right_table[i]);
	}

	strcpy(name_table[0],left_table[0]);
	strcpy(name_table[1],right_table[0]);

	int index = 2;
	tmp = get_relative(relative[0]);
	info[0].loc = 10000;
	info[1].loc = 10000-tmp;
	used[0] = true;

	int used_num = 1;
	int left_index,right_index;
	int eq_num;

	bool FLG;

	while(used_num < N){

		FLG = false;

		for(int i = 1; i < N; i++){
			if(used[i])continue;

			left_index = -1;
			for(int k = 0; k < index; k++){
				if(strCmp(name_table[k],left_table[i])){
					left_index = k;
					break;
				}
			}

			right_index = -1;
			for(int k = 0; k < index; k++){
				if(strCmp(name_table[k],right_table[i])){
					right_index = k;
					break;
				}
			}

			if(left_index != -1 || right_index != -1){
				FLG = true;
				eq_num = i;
				break;
			}
		}

		if(!FLG){
			for(int i = 1; i < N; i++){
				if(used[i])continue;

				eq_num = i;
				break;
			}

			used[eq_num] = true;
			used_num++;

			strcpy(name_table[index],left_table[eq_num]);
			strcpy(name_table[index+1],right_table[eq_num]);
			tmp = get_relative(relative[eq_num]);
			info[index].loc = 10000;
			info[index+1].loc = info[index].loc-tmp;
			index += 2;
			continue;
		}

		used[eq_num] = true;
		used_num++;

		if(left_index == -1){
			strcpy(name_table[index],left_table[eq_num]);
			tmp = get_relative(relative[eq_num]);
			info[index].loc = info[right_index].loc+tmp;
			index++;
		}else if(right_index == -1){
			strcpy(name_table[index],right_table[eq_num]);
			tmp = get_relative(relative[eq_num]);
			info[index].loc = info[left_index].loc-tmp;
			index++;
		}else{
			tmp = get_relative(relative[eq_num]);

			if(info[left_index].loc-info[right_index].loc != tmp){
				printf("No\n");
				return;
			}
		}
	}

	printf("Yes\n");
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3068