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

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

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

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

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

d.y = g
d.z = m
d.s = j
d.w = n
j.z = g
g.q = d
n.s = g
b.y = g
b.z = m
b.s = m
b.w = n
m.z = g
assert g.q.w.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: B = None
        self.s: B = None
        self.w: D = None
        self.txt = txt

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

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

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

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

d.y = g
d.z = m
d.s = j
d.w = n
j.z = g
g.q = d
n.s = g
b.y = g
b.z = m
b.s = m
b.w = n
m.z = g
assert g.q.w.s.q.txt == "d"