class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: B = None
        self.p: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: B = None
        self.txt = txt

m = A("m")
j = B("j")
b = C("b")
h = B("h")
k = A("k")
d = B("d")
i = C("i")
f = C("f")

m.u = d
m.z = i
j.r = i
j.w = h
j.p = k
b.z = k
b.r = d
h.r = b
h.w = j
h.p = k
k.u = d
k.z = f
d.r = i
d.w = h
d.p = m
i.z = m
i.r = h
f.z = m
f.r = j
assert d.w.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: B = None
        self.p: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: B = None
        self.txt = txt

m = A("m")
j = B("j")
b = C("b")
h = B("h")
k = A("k")
d = B("d")
i = C("i")
f = C("f")

m.u = d
m.z = i
j.r = i
j.w = h
j.p = k
b.z = k
b.r = d
h.r = b
h.w = j
h.p = k
k.u = d
k.z = f
d.r = i
d.w = h
d.p = m
i.z = m
i.r = h
f.z = m
f.r = j
assert d.w.w.r.txt == "i"