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

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

g = A("g")
k = B("k")
l = B("l")
j = B("j")
n = A("n")
e = B("e")
f = B("f")

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

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

g = A("g")
k = B("k")
l = B("l")
j = B("j")
n = A("n")
e = B("e")
f = B("f")

g.q = f
k.v = e
k.r = g
l.v = e
l.r = g
j.v = k
j.r = n
n.q = k
e.v = k
e.r = n
f.v = e
f.r = g
assert l.v.r.q.txt == "k"