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

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

i = A("i")
d = B("d")
f = A("f")
b = A("b")
n = B("n")
l = B("l")
h = B("h")

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

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

i = A("i")
d = B("d")
f = A("f")
b = A("b")
n = B("n")
l = B("l")
h = B("h")

i.p = n
d.y = b
f.p = l
b.p = h
n.y = b
l.y = i
h.y = i
assert f.p.y.p.y.p.y.txt == "i"