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

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

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

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

j = A("j")
a = B("a")
m = C("m")
f = D("f")

j.x = m
a.p = f
m.z = a
f.x = m
f.o = j
assert m.z.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

j = A("j")
a = B("a")
m = C("m")
f = D("f")

j.x = m
a.p = f
m.z = a
f.x = m
f.o = j
assert m.z.p.x.txt == "m"