#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

vector<pair<int, int> > edge[1000];
char str1[100];
char str2[100];
int dist[1000];

bool dfs(int now, int cost) {
  if (dist[now] != 0x0f0f0f0f) {
    return dist[now] == cost;
  }
  dist[now] = cost;
  FORIT(it, edge[now]) {
    if (!dfs(it->first, cost + it->second)) { return false; }
  }
  return true;
}

int main() {
  int n;
  while (scanf("%d", &n), n) {
REP(i, 1000) { edge[i].clear(); }
  map<string, int> open;
  int m = 0;
  REP(i, n) {
    int cost;
    scanf(" 1 %s = 10^ %d %s", str1, &cost, str2);
    if (!open.count((string)str1)) { open[(string)str1] = m++; }
    if (!open.count((string)str2)) { open[(string)str2] = m++; }
    int l = open[(string)str1];
    int r = open[(string)str2];
    edge[l].push_back(make_pair(r, -cost));
    edge[r].push_back(make_pair(l, cost));
  }
  MEMSET(dist, 0x0f);
  REP(i, m) {
    if (dist[i] != 0x0f0f0f0f) { continue; }
    if (dfs(i, 0)) {
    } else {
      puts("No");
      goto next;
    }
  }
  puts("Yes");
next:;
}
}