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

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

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

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

g = A("g")
n = B("n")
j = C("j")
m = D("m")
f = C("f")

g.q = j
g.y = n
n.z = m
j.x = m
m.y = f
m.r = f
m.s = n
f.x = m
assert g.q.x.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.y: B = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
j = C("j")
m = D("m")
f = C("f")

g.q = j
g.y = n
n.z = m
j.x = m
m.y = f
m.r = f
m.s = n
f.x = m
assert g.q.x.s.z.s.txt == "n"