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

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

h = A("h")
l = B("l")
f = B("f")
g = A("g")
i = B("i")
d = B("d")

h.y = g
h.v = g
l.p = h
f.p = g
g.y = h
g.v = h
i.p = g
d.p = h
assert h.v.v.y.y.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: A = None
        self.txt = txt

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

h = A("h")
l = B("l")
f = B("f")
g = A("g")
i = B("i")
d = B("d")

h.y = g
h.v = g
l.p = h
f.p = g
g.y = h
g.v = h
i.p = g
d.p = h
assert h.v.v.y.y.y.v.txt == "h"