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

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

g = A("g")
n = B("n")
h = A("h")
b = A("b")
c = A("c")
i = A("i")

g.y = c
g.v = n
n.q = g
h.y = i
h.v = n
b.y = h
b.v = n
c.y = g
c.v = n
i.y = c
i.v = n
assert i.v.q.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: B = None
        self.txt = txt

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

g = A("g")
n = B("n")
h = A("h")
b = A("b")
c = A("c")
i = A("i")

g.y = c
g.v = n
n.q = g
h.y = i
h.v = n
b.y = h
b.v = n
c.y = g
c.v = n
i.y = c
i.v = n
assert i.v.q.y.y.txt == "g"