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

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

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

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

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

a.q = g
a.x = d
j.o = a
j.v = g
i.z = g
g.q = n
c.q = i
n.z = c
d.q = g
d.x = a
assert a.x.q.q.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.x: A = None
        self.txt = txt

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

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

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

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

a.q = g
a.x = d
j.o = a
j.v = g
i.z = g
g.q = n
c.q = i
n.z = c
d.q = g
d.x = a
assert a.x.q.q.z.q.txt == "i"