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

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

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

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

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

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

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

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

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

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

g.o = a
g.x = a
i.s = g
i.q = f
c.z = j
c.s = j
a.r = j
f.s = g
f.q = i
j.z = c
j.s = c
assert c.z.z.z.txt == "j"