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

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

m = A("m")
g = B("g")
i = B("i")
j = B("j")
c = A("c")
d = A("d")

m.s = d
m.x = c
g.x = j
g.s = c
i.x = j
i.s = m
j.x = i
j.s = c
c.s = m
c.x = d
d.s = m
d.x = c
assert i.x.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: A = None
        self.txt = txt

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

m = A("m")
g = B("g")
i = B("i")
j = B("j")
c = A("c")
d = A("d")

m.s = d
m.x = c
g.x = j
g.s = c
i.x = j
i.s = m
j.x = i
j.s = c
c.s = m
c.x = d
d.s = m
d.x = c
assert i.x.x.s.txt == "m"