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

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

b = A("b")
f = B("f")
c = A("c")
n = B("n")
d = A("d")
m = A("m")

b.x = m
b.s = f
f.u = d
c.x = b
c.s = n
n.u = c
d.x = b
d.s = n
m.x = b
m.s = f
assert n.u.x.s.u.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: B = None
        self.txt = txt

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

b = A("b")
f = B("f")
c = A("c")
n = B("n")
d = A("d")
m = A("m")

b.x = m
b.s = f
f.u = d
c.x = b
c.s = n
n.u = c
d.x = b
d.s = n
m.x = b
m.s = f
assert n.u.x.s.u.x.x.txt == "m"