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

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

k = A("k")
h = B("h")
a = B("a")
c = B("c")
f = A("f")
j = B("j")

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

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

k = A("k")
h = B("h")
a = B("a")
c = B("c")
f = A("f")
j = B("j")

k.u = c
k.x = f
h.x = f
a.x = k
c.x = f
f.u = c
f.x = k
j.x = k
assert f.x.x.u.x.x.txt == "k"