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

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

h = A("h")
k = B("k")
e = B("e")
f = A("f")

h.s = f
h.u = f
k.x = e
k.v = f
e.x = k
e.v = h
f.s = h
f.u = h
assert h.s.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.u: A = None
        self.txt = txt

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

h = A("h")
k = B("k")
e = B("e")
f = A("f")

h.s = f
h.u = f
k.x = e
k.v = f
e.x = k
e.v = h
f.s = h
f.u = h
assert h.s.s.u.txt == "f"