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

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

l = A("l")
c = B("c")
a = B("a")
b = B("b")
h = A("h")

l.x = h
c.u = a
c.o = h
a.u = b
a.o = h
b.u = a
b.o = h
h.x = l
assert a.o.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

l = A("l")
c = B("c")
a = B("a")
b = B("b")
h = A("h")

l.x = h
c.u = a
c.o = h
a.u = b
a.o = h
b.u = a
b.o = h
h.x = l
assert a.o.x.x.x.txt == "l"