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

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

j = A("j")
g = B("g")
e = B("e")
i = B("i")
b = A("b")
a = B("a")
l = A("l")

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

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

j = A("j")
g = B("g")
e = B("e")
i = B("i")
b = A("b")
a = B("a")
l = A("l")

j.s = e
j.p = a
g.q = j
e.q = b
i.q = b
b.s = e
b.p = i
a.q = l
l.s = i
l.p = a
assert l.p.q.p.q.p.txt == "a"