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

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

d = A("d")
e = B("e")
f = A("f")
l = A("l")
h = B("h")
i = B("i")
b = B("b")
n = B("n")
j = A("j")

d.w = e
e.q = b
f.w = b
l.w = e
h.q = i
i.q = b
b.q = n
n.q = i
j.w = n
assert n.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

d = A("d")
e = B("e")
f = A("f")
l = A("l")
h = B("h")
i = B("i")
b = B("b")
n = B("n")
j = A("j")

d.w = e
e.q = b
f.w = b
l.w = e
h.q = i
i.q = b
b.q = n
n.q = i
j.w = n
assert n.q.q.q.q.q.txt == "b"