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

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

i = A("i")
b = B("b")
f = B("f")
d = A("d")
h = A("h")
e = B("e")
l = A("l")

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

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

i = A("i")
b = B("b")
f = B("f")
d = A("d")
h = A("h")
e = B("e")
l = A("l")

i.y = l
b.r = i
b.o = f
f.r = i
f.o = b
d.y = h
h.y = l
e.r = l
e.o = f
l.y = d
assert h.y.y.y.y.y.y.txt == "h"