#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;
using T = tuple<int, int, int>;

int main() {
        int n;
        while (scanf("%d", &n) && n) {
                getchar();
                map<string, int> mp;
                int nodes = 0;
                vector<T> es;
                for (int i = 0; i < n; i ++) {
                        char ss[1024], tt[1024];
                        int val;
                        scanf("1 %s = 10^%d %s", ss, &val, tt);
                        getchar();
                        string s = ss;
                        string t = tt;
                        if (!mp.count(s)) mp[s] = nodes ++;
                        if (!mp.count(t)) mp[t] = nodes ++;
                        es.push_back(make_tuple(mp[s], mp[t], val));
                }
                vector<vector<pair<int, int>>> g(nodes);
                for (int i = 0; i < n; i ++) {
                        int a, b, d;
                        tie(a, b, d) = es[i];
                        g[a].emplace_back(b, d);
                        g[b].emplace_back(a, -d);
                }
                vector<bool> used(nodes, false);
                vector<int> dist(nodes);
                bool ans = true;
                function<void (int, int)> dfs = [&](int u, int d) {
                        used[u] = true;
                        dist[u] = d;
                        for (auto e : g[u]) {
                                if (!used[e.first]) {
                                        dfs(e.first, d + e.second);
                                } else if (dist[e.first] != d + e.second) {
                                        ans = false;
                                }
                        }
                };
                for (int i = 0; i < nodes; i ++) if (!used[i]) {
                        dfs(i, 0);
                }
                puts(ans ? "Yes" : "No");
        }
        return 0;
}

