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

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

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

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

a = A("a")
b = B("b")
i = C("i")
d = D("d")
f = D("f")

a.x = d
b.o = i
b.x = f
b.u = a
i.o = d
d.y = b
d.p = b
f.y = b
f.p = b
assert i.o.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

a = A("a")
b = B("b")
i = C("i")
d = D("d")
f = D("f")

a.x = d
b.o = i
b.x = f
b.u = a
i.o = d
d.y = b
d.p = b
f.y = b
f.p = b
assert i.o.y.u.txt == "a"