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

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

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

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

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

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

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