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

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

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

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

m = A("m")
f = B("f")
n = C("n")
i = D("i")
j = A("j")

m.z = f
f.p = i
f.o = i
f.q = i
f.r = j
n.o = j
i.r = f
i.o = f
i.z = m
i.w = n
j.z = f
assert f.r.z.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

m = A("m")
f = B("f")
n = C("n")
i = D("i")
j = A("j")

m.z = f
f.p = i
f.o = i
f.q = i
f.r = j
n.o = j
i.r = f
i.o = f
i.z = m
i.w = n
j.z = f
assert f.r.z.r.z.r.txt == "j"