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

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

f = A("f")
h = B("h")
k = B("k")
m = B("m")
b = A("b")
i = B("i")
e = A("e")
a = B("a")
j = A("j")
c = B("c")

f.v = k
h.q = f
h.y = m
k.q = j
k.y = h
m.q = e
m.y = i
b.v = h
i.q = f
i.y = k
e.v = c
a.q = e
a.y = i
j.v = m
c.q = b
c.y = h
assert h.q.v.q.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

f = A("f")
h = B("h")
k = B("k")
m = B("m")
b = A("b")
i = B("i")
e = A("e")
a = B("a")
j = A("j")
c = B("c")

f.v = k
h.q = f
h.y = m
k.q = j
k.y = h
m.q = e
m.y = i
b.v = h
i.q = f
i.y = k
e.v = c
a.q = e
a.y = i
j.v = m
c.q = b
c.y = h
assert h.q.v.q.v.y.txt == "i"