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

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

m = A("m")
g = B("g")
n = B("n")
b = A("b")
c = B("c")
d = A("d")
a = A("a")

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

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

m = A("m")
g = B("g")
n = B("n")
b = A("b")
c = B("c")
d = A("d")
a = A("a")

m.s = c
m.u = b
g.t = m
n.t = b
b.s = c
b.u = a
c.t = b
d.s = c
d.u = b
a.s = c
a.u = b
assert m.u.u.s.t.u.txt == "a"