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

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

n = A("n")
e = B("e")
c = B("c")
d = A("d")
a = B("a")
h = B("h")

n.s = c
n.y = h
e.o = d
e.x = c
c.o = n
c.x = h
d.s = h
d.y = c
a.o = d
a.x = e
h.o = n
h.x = c
assert c.o.s.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: B = None
        self.txt = txt

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

n = A("n")
e = B("e")
c = B("c")
d = A("d")
a = B("a")
h = B("h")

n.s = c
n.y = h
e.o = d
e.x = c
c.o = n
c.x = h
d.s = h
d.y = c
a.o = d
a.x = e
h.o = n
h.x = c
assert c.o.s.x.o.txt == "n"