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

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

g = A("g")
l = B("l")
f = B("f")
m = B("m")
c = B("c")
i = A("i")
n = B("n")
d = A("d")
k = B("k")
j = B("j")

g.p = c
g.q = d
l.o = c
f.o = l
m.o = k
c.o = j
i.p = k
i.q = d
n.o = l
d.p = f
d.q = i
k.o = l
j.o = l
assert l.o.o.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: A = None
        self.txt = txt

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

g = A("g")
l = B("l")
f = B("f")
m = B("m")
c = B("c")
i = A("i")
n = B("n")
d = A("d")
k = B("k")
j = B("j")

g.p = c
g.q = d
l.o = c
f.o = l
m.o = k
c.o = j
i.p = k
i.q = d
n.o = l
d.p = f
d.q = i
k.o = l
j.o = l
assert l.o.o.o.o.o.o.o.o.o.txt == "l"