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

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: 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.x: B = None
        self.p: B = None
        self.s: A = None
        self.txt = txt

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

m.w = f
f.p = m
f.r = g
g.q = m
j.x = f
j.p = f
j.s = m
e.x = k
e.p = f
e.s = m
k.p = m
k.r = g
assert k.p.w.r.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: 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.x: B = None
        self.p: B = None
        self.s: A = None
        self.txt = txt

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

m.w = f
f.p = m
f.r = g
g.q = m
j.x = f
j.p = f
j.s = m
e.x = k
e.p = f
e.s = m
k.p = m
k.r = g
assert k.p.w.r.q.w.r.txt == "g"