#include<bits/stdc++.h>
#define lp(i,n) for(int i=0;i<n;i++)
using namespace std;

const int INF=1e9;
struct edge{
    int to, cost;
};
string a[105], b[105];
int c[105];
vector<edge> G[210];

bool dfs(int v, vector<int> &dist)
{
    for(edge e:G[v]){
        if(dist[e.to]==INF){
            dist[e.to]=dist[v]+e.cost;
            if(!dfs(e.to, dist)) return false;
        }else{
            if(dist[e.to]!=dist[v]+e.cost){
                return false;
            }
        }
    }
    return true;
}

int main()
{
while(true)
{
    int N; cin>>N;
    if(N==0) break;

    vector<string> vs;
    for(int i=0;i<N;i++){
      int x,y;
      string s1,s2,s3,s4;
      cin>>x>>s1>>s2>>s3>>s4;
      lp(i,s3.size()){
        if(s3[i]=='^'){
          s3=s3.substr(i+1,s3.size()-i-1);
          y=stoi(s3);
          break;
        }
      }
      a[i]=s1;
      b[i]=s4;
      c[i]=y;
      vs.push_back(a[i]);
      vs.push_back(b[i]);
      //cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<endl;
    }
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());

    map<string, int> mp;
    for(int i=0;i<vs.size();i++){
        mp[vs[i]]=i;
    }

    int V=vs.size();
    for(int i=0;i<V;i++){
        G[i].clear();
    }
    for(int i=0;i<N;i++){
        int v=mp[a[i]];
        int u=mp[b[i]];
        G[v].push_back({u, c[i]});
        G[u].push_back({v, -c[i]});
    }
/*
    for(int i=0;i<V;i++){
        cout<<i<<' ';
        for(edge e:G[i]){
            cout<<e.to<<' '<<e.cost<<endl;
        }
        cout<<"----------"<<endl;
    }
*/
    vector<int> dist(V, INF);
    bool ok=true;
    for(int i=0;i<V;i++){
        if(dist[i]!=INF) continue;
        dist[i]=0;
        if(!dfs(i, dist)){
            ok=false;
        }
    }
    cout<<(ok? "Yes":"No")<<endl;
}
}



