class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

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

m.p = c
g.q = m
g.z = f
b.y = m
b.z = c
k.w = b
c.w = b
f.q = m
f.z = g
e.w = b
assert f.q.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

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

m.p = c
g.q = m
g.z = f
b.y = m
b.z = c
k.w = b
c.w = b
f.q = m
f.z = g
e.w = b
assert f.q.p.w.txt == "b"