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

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

m = A("m")
g = B("g")
a = B("a")
j = B("j")
c = A("c")
d = A("d")

m.v = c
g.u = d
g.t = j
a.u = m
a.t = j
j.u = m
j.t = g
c.v = m
d.v = c
assert g.t.t.t.u.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

m = A("m")
g = B("g")
a = B("a")
j = B("j")
c = A("c")
d = A("d")

m.v = c
g.u = d
g.t = j
a.u = m
a.t = j
j.u = m
j.t = g
c.v = m
d.v = c
assert g.t.t.t.u.v.v.txt == "m"