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

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

a = A("a")
h = B("h")
l = B("l")
n = A("n")
f = B("f")
b = A("b")

a.o = b
h.w = b
l.w = a
n.o = a
f.w = n
b.o = a
assert b.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.w: A = None
        self.txt = txt

a = A("a")
h = B("h")
l = B("l")
n = A("n")
f = B("f")
b = A("b")

a.o = b
h.w = b
l.w = a
n.o = a
f.w = n
b.o = a
assert b.o.o.o.o.o.o.txt == "b"