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

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

j = A("j")
g = B("g")
f = A("f")
i = B("i")
c = A("c")
a = B("a")
e = A("e")
h = A("h")

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

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

j = A("j")
g = B("g")
f = A("f")
i = B("i")
c = A("c")
a = B("a")
e = A("e")
h = A("h")

j.q = g
j.y = e
g.q = h
f.q = i
f.y = e
i.q = c
c.q = a
c.y = h
a.q = e
e.q = a
e.y = j
h.q = g
h.y = j
assert h.q.q.q.q.txt == "h"