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

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

n = A("n")
k = B("k")
g = B("g")
h = A("h")
i = B("i")

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

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

n = A("n")
k = B("k")
g = B("g")
h = A("h")
i = B("i")

n.v = g
n.o = i
k.q = n
g.q = n
h.v = i
h.o = k
i.q = h
assert i.q.o.q.v.txt == "g"