class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

i = A("i")
m = B("m")
g = C("g")
a = D("a")

i.y = m
m.t = a
m.u = g
g.r = i
a.z = m
a.u = m
a.o = m
assert a.u.t.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

i = A("i")
m = B("m")
g = C("g")
a = D("a")

i.y = m
m.t = a
m.u = g
g.r = i
a.z = m
a.u = m
a.o = m
assert a.u.t.o.u.txt == "g"