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.y: B = None
        self.txt = txt

l = A("l")
m = B("m")
d = A("d")
g = A("g")
b = B("b")
e = A("e")
k = A("k")
h = B("h")

l.p = m
l.w = h
m.y = h
d.p = h
d.w = b
g.p = h
g.w = b
b.y = m
e.p = m
e.w = b
k.p = m
k.w = h
h.y = b
assert b.y.y.y.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.y: B = None
        self.txt = txt

l = A("l")
m = B("m")
d = A("d")
g = A("g")
b = B("b")
e = A("e")
k = A("k")
h = B("h")

l.p = m
l.w = h
m.y = h
d.p = h
d.w = b
g.p = h
g.w = b
b.y = m
e.p = m
e.w = b
k.p = m
k.w = h
h.y = b
assert b.y.y.y.txt == "b"