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

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

d = A("d")
i = B("i")
b = C("b")
j = D("j")

d.o = b
i.p = b
b.r = j
b.p = i
b.v = d
j.o = i
j.p = i
j.y = b
j.s = b
assert i.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: 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.r: D = None
        self.p: B = None
        self.v: A = None
        self.txt = txt

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

d = A("d")
i = B("i")
b = C("b")
j = D("j")

d.o = b
i.p = b
b.r = j
b.p = i
b.v = d
j.o = i
j.p = i
j.y = b
j.s = b
assert i.p.r.p.txt == "i"