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

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

k = A("k")
e = B("e")
c = B("c")
d = A("d")
f = A("f")
n = A("n")
g = A("g")
h = A("h")
j = A("j")

k.q = j
k.x = c
e.v = c
c.v = e
d.q = g
d.x = e
f.q = h
f.x = c
n.q = f
n.x = c
g.q = f
g.x = e
h.q = k
h.x = e
j.q = h
j.x = e
assert g.q.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.x: B = None
        self.txt = txt

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

k = A("k")
e = B("e")
c = B("c")
d = A("d")
f = A("f")
n = A("n")
g = A("g")
h = A("h")
j = A("j")

k.q = j
k.x = c
e.v = c
c.v = e
d.q = g
d.x = e
f.q = h
f.x = c
n.q = f
n.x = c
g.q = f
g.x = e
h.q = k
h.x = e
j.q = h
j.x = e
assert g.q.x.v.v.txt == "c"