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

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

h = A("h")
m = B("m")
j = B("j")
k = B("k")
b = A("b")
f = A("f")

h.p = m
m.p = j
m.y = h
j.p = m
j.y = f
k.p = m
k.y = b
b.p = k
f.p = j
assert b.p.p.y.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

h = A("h")
m = B("m")
j = B("j")
k = B("k")
b = A("b")
f = A("f")

h.p = m
m.p = j
m.y = h
j.p = m
j.y = f
k.p = m
k.y = b
b.p = k
f.p = j
assert b.p.p.y.p.y.p.txt == "m"