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

class B:
    def __init__(self, txt: str):
        self.y: A = 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.z: C = None
        self.o: A = None
        self.p: B = None
        self.txt = txt

d = A("d")
k = B("k")
l = C("l")
b = D("b")

d.p = b
d.v = b
k.y = d
l.z = k
b.z = l
b.o = d
b.p = k
assert b.z.z.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.v: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = 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.z: C = None
        self.o: A = None
        self.p: B = None
        self.txt = txt

d = A("d")
k = B("k")
l = C("l")
b = D("b")

d.p = b
d.v = b
k.y = d
l.z = k
b.z = l
b.o = d
b.p = k
assert b.z.z.y.v.txt == "b"