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

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

n = A("n")
e = B("e")
c = B("c")
b = A("b")
h = B("h")
m = B("m")
g = A("g")

n.x = e
n.w = g
e.x = h
e.r = n
c.x = m
c.r = b
b.x = h
b.w = n
h.x = m
h.r = b
m.x = e
m.r = g
g.x = h
g.w = n
assert m.x.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: A = None
        self.txt = txt

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

n = A("n")
e = B("e")
c = B("c")
b = A("b")
h = B("h")
m = B("m")
g = A("g")

n.x = e
n.w = g
e.x = h
e.r = n
c.x = m
c.r = b
b.x = h
b.w = n
h.x = m
h.r = b
m.x = e
m.r = g
g.x = h
g.w = n
assert m.x.r.w.txt == "g"