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

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

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

e.r = g
e.p = c
a.o = g
g.o = f
j.r = a
j.p = e
c.r = f
c.p = e
f.o = g
i.r = f
i.p = c
assert c.p.p.p.r.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: A = None
        self.txt = txt

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

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

e.r = g
e.p = c
a.o = g
g.o = f
j.r = a
j.p = e
c.r = f
c.p = e
f.o = g
i.r = f
i.p = c
assert c.p.p.p.r.o.o.o.txt == "f"