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

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

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

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

j = A("j")
d = B("d")
i = C("i")
n = D("n")

j.x = d
j.q = d
j.z = n
d.o = i
d.y = i
i.o = d
i.q = d
i.t = d
n.z = j
n.p = j
n.t = i
n.q = d
assert i.t.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: D = None
        self.q: B = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
i = C("i")
n = D("n")

j.x = d
j.q = d
j.z = n
d.o = i
d.y = i
i.o = d
i.q = d
i.t = d
n.z = j
n.p = j
n.t = i
n.q = d
assert i.t.o.o.txt == "d"