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

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

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

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

j = A("j")
m = B("m")
e = C("e")
g = D("g")
c = C("c")

j.u = g
m.o = j
m.z = g
e.o = j
g.q = m
g.z = m
g.t = c
c.o = j
assert e.o.u.t.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
e = C("e")
g = D("g")
c = C("c")

j.u = g
m.o = j
m.z = g
e.o = j
g.q = m
g.z = m
g.t = c
c.o = j
assert e.o.u.t.o.u.txt == "g"