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

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

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

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

m = A("m")
h = B("h")
g = C("g")
n = D("n")

m.q = n
m.x = h
h.q = m
h.w = n
g.y = m
g.r = n
g.w = n
g.x = h
n.s = g
assert n.s.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.x: B = None
        self.txt = txt

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

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

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

m = A("m")
h = B("h")
g = C("g")
n = D("n")

m.q = n
m.x = h
h.q = m
h.w = n
g.y = m
g.r = n
g.w = n
g.x = h
n.s = g
assert n.s.x.w.txt == "n"