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

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

b = A("b")
e = B("e")
a = B("a")
k = A("k")
l = A("l")
g = B("g")
h = B("h")
i = A("i")

b.x = l
b.v = a
e.x = h
e.q = g
a.x = h
a.q = h
k.x = b
k.v = g
l.x = b
l.v = a
g.x = a
g.q = h
h.x = g
h.q = g
i.x = k
i.v = a
assert k.x.v.q.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.v: B = None
        self.txt = txt

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

b = A("b")
e = B("e")
a = B("a")
k = A("k")
l = A("l")
g = B("g")
h = B("h")
i = A("i")

b.x = l
b.v = a
e.x = h
e.q = g
a.x = h
a.q = h
k.x = b
k.v = g
l.x = b
l.v = a
g.x = a
g.q = h
h.x = g
h.q = g
i.x = k
i.v = a
assert k.x.v.q.x.x.x.txt == "h"