#include<cstdio>
#include<climits>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef map<string,int>M;
const int N=200,X=INT_MAX/6;
int main()
{
	int x[N][N],n,i,j,k,a,b;
	char s[64],t[64];
	while(scanf("%d",&n),n)
	{
		for(i=0;i<N;++i)for(j=0;j<N;++j)x[i][j]=X;
		M m;
		M::iterator ite;
		while(n--)
		{
			scanf(" 1 %s = 10^%d %s",s,&k,t);
			if((ite=m.find(s))==m.end())
			{
				a=m.size();
				m[s]=a;
			}
			else a=ite->second;
			if((ite=m.find(t))==m.end())
			{
				b=m.size();
				m[t]=b;
			}
			else b=ite->second;
			x[a][b]=k;
			x[b][a]=-k;
		}
		b=m.size();
		for(k=0;k<b;++k)for(i=0;i<b;++i)for(j=0;j<b;++j)
			x[i][j]=min(x[i][j],x[i][k]+x[k][j]);
		for(a=i=0;i<b;++i)if(x[i][i]<0){a=1;break;}
		puts(a?"No":"Yes");
	}
	return 0;
}