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

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

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

class D:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

a.z = l
a.q = g
a.r = i
l.o = g
l.t = a
i.q = l
i.u = l
g.x = i
assert l.o.x.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: D = None
        self.r: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

a.z = l
a.q = g
a.r = i
l.o = g
l.t = a
i.q = l
i.u = l
g.x = i
assert l.o.x.q.o.txt == "g"