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

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

f = A("f")
g = B("g")
i = A("i")
m = B("m")

f.s = g
f.t = m
g.u = i
g.s = i
i.s = g
i.t = g
m.u = f
m.s = i
assert g.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.t: B = None
        self.txt = txt

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

f = A("f")
g = B("g")
i = A("i")
m = B("m")

f.s = g
f.t = m
g.u = i
g.s = i
i.s = g
i.t = g
m.u = f
m.s = i
assert g.s.s.s.txt == "i"