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

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

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

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

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

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

i.w = d
i.p = k
j.q = b
e.w = d
e.p = j
k.q = b
d.w = e
d.p = k
b.q = a
a.q = b
m.w = d
m.p = k
assert d.w.p.q.q.q.txt == "b"