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

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

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

i = A("i")
k = B("k")
e = C("e")
d = C("d")

i.u = e
k.u = i
k.x = e
e.z = i
e.o = k
e.r = d
d.z = i
d.o = k
d.r = e
assert d.o.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
e = C("e")
d = C("d")

i.u = e
k.u = i
k.x = e
e.z = i
e.o = k
e.r = d
d.z = i
d.o = k
d.r = e
assert d.o.x.o.x.txt == "e"