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

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

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

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

d = A("d")
h = B("h")
c = C("c")
b = D("b")
e = A("e")

d.y = b
d.p = b
h.p = b
h.o = c
c.o = b
c.v = h
b.p = c
b.x = d
e.y = b
e.p = b
assert d.p.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.p: D = None
        self.txt = txt

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

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

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

d = A("d")
h = B("h")
c = C("c")
b = D("b")
e = A("e")

d.y = b
d.p = b
h.p = b
h.o = c
c.o = b
c.v = h
b.p = c
b.x = d
e.y = b
e.p = b
assert d.p.p.v.txt == "h"