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

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

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

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

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

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

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