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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: A = None
        self.txt = txt

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

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

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

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

class B:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: A = None
        self.txt = txt

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

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

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

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