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

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

f = A("f")
j = B("j")
e = A("e")
i = A("i")
l = A("l")
b = A("b")
a = A("a")
c = B("c")

f.q = a
f.v = i
j.r = a
j.x = a
e.q = a
e.v = i
i.q = e
i.v = b
l.q = b
l.v = a
b.q = l
b.v = e
a.q = e
a.v = b
c.r = i
c.x = f
assert b.q.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.v: A = None
        self.txt = txt

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

f = A("f")
j = B("j")
e = A("e")
i = A("i")
l = A("l")
b = A("b")
a = A("a")
c = B("c")

f.q = a
f.v = i
j.r = a
j.x = a
e.q = a
e.v = i
i.q = e
i.v = b
l.q = b
l.v = a
b.q = l
b.v = e
a.q = e
a.v = b
c.r = i
c.x = f
assert b.q.v.q.v.txt == "i"