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

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

n = A("n")
i = B("i")
f = A("f")
j = B("j")
h = B("h")
c = B("c")

n.x = j
n.q = f
i.y = c
i.o = n
f.x = c
f.q = n
j.y = h
j.o = f
h.y = c
h.o = f
c.y = j
c.o = n
assert f.x.o.q.x.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.q: A = None
        self.txt = txt

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

n = A("n")
i = B("i")
f = A("f")
j = B("j")
h = B("h")
c = B("c")

n.x = j
n.q = f
i.y = c
i.o = n
f.x = c
f.q = n
j.y = h
j.o = f
h.y = c
h.o = f
c.y = j
c.o = n
assert f.x.o.q.x.o.q.txt == "f"