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

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

g = A("g")
a = B("a")
n = A("n")
h = A("h")
c = B("c")

g.q = a
g.y = h
a.u = n
a.w = n
n.q = c
n.y = g
h.q = c
h.y = n
c.u = g
c.w = n
assert h.y.q.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: A = None
        self.txt = txt

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

g = A("g")
a = B("a")
n = A("n")
h = A("h")
c = B("c")

g.q = a
g.y = h
a.u = n
a.w = n
n.q = c
n.y = g
h.q = c
h.y = n
c.u = g
c.w = n
assert h.y.q.u.y.txt == "h"