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

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

f = A("f")
h = B("h")
m = B("m")

f.o = m
f.u = h
h.x = m
m.x = h
assert m.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: B = None
        self.txt = txt

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

f = A("f")
h = B("h")
m = B("m")

f.o = m
f.u = h
h.x = m
m.x = h
assert m.x.x.x.txt == "h"