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

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

g = A("g")
a = B("a")
l = B("l")
i = A("i")
j = A("j")
b = B("b")
k = A("k")
d = A("d")
m = B("m")

g.w = a
g.p = a
a.x = m
l.x = m
i.w = m
i.p = a
j.w = b
j.p = l
b.x = m
k.w = b
k.p = b
d.w = b
d.p = b
m.x = b
assert m.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: B = None
        self.txt = txt

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

g = A("g")
a = B("a")
l = B("l")
i = A("i")
j = A("j")
b = B("b")
k = A("k")
d = A("d")
m = B("m")

g.w = a
g.p = a
a.x = m
l.x = m
i.w = m
i.p = a
j.w = b
j.p = l
b.x = m
k.w = b
k.p = b
d.w = b
d.p = b
m.x = b
assert m.x.x.x.x.x.x.x.txt == "b"