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

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

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

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

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

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

l.r = g
b.o = l
b.p = m
c.o = g
c.p = m
i.o = g
i.p = b
m.o = g
m.p = i
g.r = l
e.o = g
e.p = m
assert e.p.p.o.r.r.r.r.txt == "g"