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

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

d = A("d")
i = B("i")
a = B("a")
f = A("f")
h = A("h")
g = A("g")
l = B("l")

d.o = f
i.o = d
i.x = a
a.o = f
a.x = l
f.o = d
h.o = d
g.o = d
l.o = f
l.x = a
assert l.o.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.o: A = None
        self.x: B = None
        self.txt = txt

d = A("d")
i = B("i")
a = B("a")
f = A("f")
h = A("h")
g = A("g")
l = B("l")

d.o = f
i.o = d
i.x = a
a.o = f
a.x = l
f.o = d
h.o = d
g.o = d
l.o = f
l.x = a
assert l.o.o.o.o.o.o.o.txt == "f"