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

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

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

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

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

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

l.p = f
l.q = a
j.w = l
j.q = e
k.w = e
k.q = e
g.w = l
g.q = l
i.w = e
i.q = l
a.w = l
a.q = l
b.w = l
b.q = l
e.p = j
e.q = b
c.w = e
c.q = e
f.w = e
f.q = l
assert e.p.q.q.q.p.q.txt == "l"