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

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

b = A("b")
i = B("i")
n = B("n")
j = A("j")
l = B("l")
g = B("g")
h = A("h")

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

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

b = A("b")
i = B("i")
n = B("n")
j = A("j")
l = B("l")
g = B("g")
h = A("h")

b.q = h
b.w = g
i.q = b
n.q = b
j.q = b
j.w = g
l.q = b
g.q = b
h.q = j
h.w = g
assert j.q.q.w.q.w.q.txt == "b"