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

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

l = A("l")
m = B("m")
h = B("h")
c = B("c")
k = A("k")
n = B("n")
f = A("f")
g = B("g")
a = B("a")
b = A("b")

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

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

l = A("l")
m = B("m")
h = B("h")
c = B("c")
k = A("k")
n = B("n")
f = A("f")
g = B("g")
a = B("a")
b = A("b")

l.o = b
m.r = h
h.r = a
c.r = n
k.o = f
n.r = c
f.o = l
g.r = a
a.r = n
b.o = k
assert c.r.r.r.txt == "n"