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

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

d = A("d")
b = B("b")
n = B("n")
g = A("g")
h = A("h")
a = B("a")
i = A("i")
e = A("e")

d.s = e
b.q = a
b.w = a
n.q = b
n.w = a
g.s = d
h.s = g
a.q = n
a.w = b
i.s = h
e.s = i
assert b.q.q.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

d = A("d")
b = B("b")
n = B("n")
g = A("g")
h = A("h")
a = B("a")
i = A("i")
e = A("e")

d.s = e
b.q = a
b.w = a
n.q = b
n.w = a
g.s = d
h.s = g
a.q = n
a.w = b
i.s = h
e.s = i
assert b.q.q.w.w.txt == "b"