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

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

e = A("e")
g = B("g")
b = A("b")
i = A("i")
c = A("c")
k = B("k")
d = A("d")
l = B("l")

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

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

e = A("e")
g = B("g")
b = A("b")
i = A("i")
c = A("c")
k = B("k")
d = A("d")
l = B("l")

e.p = b
e.o = k
g.q = b
b.p = i
b.o = g
i.p = b
i.o = g
c.p = b
c.o = g
k.q = d
d.p = b
d.o = g
l.q = c
assert b.o.q.p.p.txt == "b"