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

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

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

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

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

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

f.o = h
m.r = l
m.y = i
h.o = k
i.o = f
l.o = k
a.o = i
k.o = l
g.r = a
g.y = f
b.r = i
b.y = l
assert a.o.o.o.o.o.o.txt == "k"