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

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

g = A("g")
c = B("c")
d = A("d")
e = B("e")
a = B("a")
m = A("m")
b = A("b")
k = A("k")

g.u = c
c.q = e
c.v = d
d.u = c
e.q = a
e.v = k
a.q = e
a.v = g
m.u = a
b.u = e
k.u = a
assert c.v.u.q.q.q.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

g = A("g")
c = B("c")
d = A("d")
e = B("e")
a = B("a")
m = A("m")
b = A("b")
k = A("k")

g.u = c
c.q = e
c.v = d
d.u = c
e.q = a
e.v = k
a.q = e
a.v = g
m.u = a
b.u = e
k.u = a
assert c.v.u.q.q.q.v.u.txt == "a"