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

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

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

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

i = A("i")
c = B("c")
a = C("a")
d = D("d")

i.q = d
c.o = a
c.t = a
a.x = c
a.q = c
d.p = c
d.z = c
d.w = c
d.t = i
assert i.q.z.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

i = A("i")
c = B("c")
a = C("a")
d = D("d")

i.q = d
c.o = a
c.t = a
a.x = c
a.q = c
d.p = c
d.z = c
d.w = c
d.t = i
assert i.q.z.o.q.txt == "c"