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

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

j = A("j")
h = B("h")
m = B("m")
i = A("i")

j.u = h
j.v = m
h.t = j
h.q = i
m.t = i
m.q = i
i.u = h
i.v = h
assert j.u.t.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: B = None
        self.txt = txt

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

j = A("j")
h = B("h")
m = B("m")
i = A("i")

j.u = h
j.v = m
h.t = j
h.q = i
m.t = i
m.q = i
i.u = h
i.v = h
assert j.u.t.v.q.txt == "i"