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.y: A = None
        self.txt = txt

k = A("k")
m = B("m")
h = B("h")
i = A("i")
g = A("g")

k.q = m
m.v = h
m.y = i
h.v = m
h.y = i
i.q = h
g.q = m
assert g.q.v.y.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: B = None
        self.y: A = None
        self.txt = txt

k = A("k")
m = B("m")
h = B("h")
i = A("i")
g = A("g")

k.q = m
m.v = h
m.y = i
h.v = m
h.y = i
i.q = h
g.q = m
assert g.q.v.y.q.v.txt == "m"