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

n = A("n")
h = B("h")
c = B("c")
j = B("j")
b = A("b")
e = A("e")
g = A("g")
l = A("l")
k = A("k")
d = B("d")

n.q = c
h.y = d
c.y = d
j.y = d
b.q = j
e.q = h
g.q = d
l.q = c
k.q = j
d.y = j
assert d.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

n = A("n")
h = B("h")
c = B("c")
j = B("j")
b = A("b")
e = A("e")
g = A("g")
l = A("l")
k = A("k")
d = B("d")

n.q = c
h.y = d
c.y = d
j.y = d
b.q = j
e.q = h
g.q = d
l.q = c
k.q = j
d.y = j
assert d.y.y.y.y.y.y.y.txt == "j"