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

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

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

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

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

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

i.q = l
b.p = j
n.q = e
h.q = j
d.q = b
c.q = j
j.p = l
g.q = j
e.p = j
l.p = b
assert h.q.p.p.p.p.p.p.p.p.p.txt == "j"