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

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

m = A("m")
h = B("h")
n = A("n")
k = B("k")
e = A("e")
c = B("c")
j = A("j")
d = B("d")
f = B("f")

m.t = j
h.u = c
h.v = m
n.t = m
k.u = c
k.v = e
e.t = n
c.u = f
c.v = n
j.t = n
d.u = f
d.v = e
f.u = k
f.v = j
assert m.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

m = A("m")
h = B("h")
n = A("n")
k = B("k")
e = A("e")
c = B("c")
j = A("j")
d = B("d")
f = B("f")

m.t = j
h.u = c
h.v = m
n.t = m
k.u = c
k.v = e
e.t = n
c.u = f
c.v = n
j.t = n
d.u = f
d.v = e
f.u = k
f.v = j
assert m.t.t.t.txt == "m"