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

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

h = A("h")
b = B("b")
g = B("g")
c = A("c")
d = B("d")
m = B("m")
i = B("i")
n = A("n")

h.w = d
b.p = i
g.p = d
c.w = i
d.p = g
m.p = b
i.p = b
n.w = i
assert b.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

h = A("h")
b = B("b")
g = B("g")
c = A("c")
d = B("d")
m = B("m")
i = B("i")
n = A("n")

h.w = d
b.p = i
g.p = d
c.w = i
d.p = g
m.p = b
i.p = b
n.w = i
assert b.p.p.p.p.txt == "b"