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

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

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

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

f = A("f")
b = B("b")
c = C("c")
d = D("d")

f.o = c
b.r = f
b.p = f
b.z = d
c.y = d
c.p = b
d.v = c
assert b.p.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
c = C("c")
d = D("d")

f.o = c
b.r = f
b.p = f
b.z = d
c.y = d
c.p = b
d.v = c
assert b.p.o.y.txt == "d"