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

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

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

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

e = A("e")
f = B("f")
d = C("d")
k = D("k")

e.x = f
f.o = e
f.x = k
d.x = f
d.o = k
d.y = k
d.u = e
k.p = f
assert e.x.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

e = A("e")
f = B("f")
d = C("d")
k = D("k")

e.x = f
f.o = e
f.x = k
d.x = f
d.o = k
d.y = k
d.u = e
k.p = f
assert e.x.x.p.txt == "f"