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

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

f = A("f")
h = B("h")
e = B("e")
b = A("b")
c = B("c")
j = B("j")

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

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

f = A("f")
h = B("h")
e = B("e")
b = A("b")
c = B("c")
j = B("j")

f.x = b
f.u = c
h.o = b
e.o = f
b.x = f
b.u = c
c.o = f
j.o = f
assert j.o.u.o.x.u.o.txt == "f"