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

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

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

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

m = A("m")
l = B("l")
g = C("g")
f = D("f")

m.p = g
m.z = g
l.o = m
g.r = m
f.w = l
f.x = m
assert g.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.z: C = None
        self.txt = txt

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

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

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

m = A("m")
l = B("l")
g = C("g")
f = D("f")

m.p = g
m.z = g
l.o = m
g.r = m
f.w = l
f.x = m
assert g.r.z.r.txt == "m"