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

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

g = A("g")
j = B("j")
b = B("b")
i = B("i")
f = A("f")
a = A("a")

g.q = i
j.v = a
j.q = b
b.v = f
b.q = i
i.v = g
i.q = j
f.q = b
a.q = b
assert f.q.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

g = A("g")
j = B("j")
b = B("b")
i = B("i")
f = A("f")
a = A("a")

g.q = i
j.v = a
j.q = b
b.v = f
b.q = i
i.v = g
i.q = j
f.q = b
a.q = b
assert f.q.q.v.txt == "g"