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

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

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

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

a = A("a")
l = B("l")
h = C("h")
g = D("g")
n = C("n")

a.s = n
a.z = g
a.r = g
l.x = g
l.s = n
h.q = g
g.v = n
n.q = g
assert l.x.v.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.z: D = None
        self.r: D = None
        self.txt = txt

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

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

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

a = A("a")
l = B("l")
h = C("h")
g = D("g")
n = C("n")

a.s = n
a.z = g
a.r = g
l.x = g
l.s = n
h.q = g
g.v = n
n.q = g
assert l.x.v.q.v.q.txt == "g"