#include
using namespace std;
using LL = int64_t;
using LD = long double;
const LL INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
template
struct LnBase{
int sz, szc;
T *x;
int *y;
LnBase (){x = 0; sz = sizeof(T) <<3; szc = -1; resize(sz);}
void resize(int size){
sz = size; if(!x) delete(x); x = new T[sz + 2]; y = new int[sz + 2];
memset(x, 0, sz * sizeof(T)); memset(y, 0, sz <<2);
}
T operator[](int h){return x[h];}
int add(T v){
for(int i = sz - 1; i >= 0; i--)
if(v & (T)1 <if(!x[i]){x[i] = v; szc = -1; return i;} v ^= x[i];}
return -1;
}
int find(T v){
for(int i = sz - 1; i >= 0; i--){
if(v & (T)1 <if(!v) return 1;}
return 0;
}
T Max(){
T s = 0;
for(int i = sz - 1; i >= 0; i--){if((s ^ x[i]) > s) s ^= x[i];}
return s;
}
T Min(){
for(int i = 0; i if(x[i]) return x[i];
return -1;
}
void Canonicity(){
int i, j;
for(i = sz - 1; i > 0; i--)
for(j = i - 1; j >= 0; j--) if(x[i] & (T)1 < x[j];
for(szc = i = 0; i if(x[i]) y[szc++] = i;
}
T Kth(long long K){
if(szc <0) Canonicity(); if(K >= 1ll <return -1; T s = 0;
for(int i = szc - 1; i >= 0; i--) if(K & 1ll < x[y[i]];
return s;
}
};
struct node {
__int128 a, t;
bool operator<(const node &e) const { return t > e.t; }
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
n--;
vector a(n);
for (auto &i : a) {
LL u, v, a, t;
cin >> u >> v >> a >> t;
i.a = a;
i.t = u ^ v ^ t;
}
sort(a.begin(), a.end());
int flag = 1;
__int128 ans = 0, sum = 0;
LnBase<__int128> b;
for (auto& s : a) {
sum += s.t;
if (s.a == 1) continue;
flag = 0;
if (b.add(s.a) != -1) ans += s.t;
}
if (flag) cout <<"No\n";
else {
ans = sum - ans;
string s = "";
while (ans) {
s += '0' + ans % 10;
ans /= 10;
}
if (s == "") s = "0";
reverse(s.begin(), s.end());
cout <'\n';
}
}