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

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

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

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

b = A("b")
d = B("d")
e = C("e")
h = D("h")
k = D("k")
c = A("c")
f = C("f")
j = A("j")
l = C("l")

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

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

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

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

b = A("b")
d = B("d")
e = C("e")
h = D("h")
k = D("k")
c = A("c")
f = C("f")
j = A("j")
l = C("l")

b.y = h
d.p = c
d.y = b
e.y = d
h.o = k
k.o = h
c.y = h
f.y = d
j.y = h
l.y = d
assert d.p.y.o.o.txt == "h"