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

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

b = A("b")
c = B("c")
m = A("m")
h = B("h")
j = B("j")
a = A("a")
d = B("d")

b.q = a
c.q = a
m.q = a
h.q = b
j.q = m
a.q = b
d.q = b
assert h.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

b = A("b")
c = B("c")
m = A("m")
h = B("h")
j = B("j")
a = A("a")
d = B("d")

b.q = a
c.q = a
m.q = a
h.q = b
j.q = m
a.q = b
d.q = b
assert h.q.q.q.txt == "b"