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

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

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

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

f = A("f")
i = B("i")
d = C("d")
n = D("n")

f.u = d
i.p = d
d.u = f
n.u = d
n.o = f
n.v = f
n.y = i
assert i.p.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

f = A("f")
i = B("i")
d = C("d")
n = D("n")

f.u = d
i.p = d
d.u = f
n.u = d
n.o = f
n.v = f
n.y = i
assert i.p.u.u.txt == "d"