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

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

f = A("f")
h = B("h")
j = B("j")
n = A("n")
c = A("c")
a = A("a")
g = A("g")
k = A("k")
b = B("b")

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

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

f = A("f")
h = B("h")
j = B("j")
n = A("n")
c = A("c")
a = A("a")
g = A("g")
k = A("k")
b = B("b")

f.q = b
h.y = b
j.y = b
n.q = h
c.q = h
a.q = b
g.q = b
k.q = h
b.y = j
assert h.y.y.y.y.y.y.y.y.txt == "j"