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

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

i = A("i")
c = B("c")
b = B("b")
k = A("k")
d = B("d")
a = B("a")
f = A("f")
n = A("n")
l = A("l")
g = B("g")

i.r = a
c.o = b
b.o = g
k.r = d
d.o = b
a.o = b
f.r = d
n.r = a
l.r = a
g.o = a
assert k.r.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

i = A("i")
c = B("c")
b = B("b")
k = A("k")
d = B("d")
a = B("a")
f = A("f")
n = A("n")
l = A("l")
g = B("g")

i.r = a
c.o = b
b.o = g
k.r = d
d.o = b
a.o = b
f.r = d
n.r = a
l.r = a
g.o = a
assert k.r.o.o.o.o.o.o.o.txt == "b"