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

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

m = A("m")
h = B("h")
b = B("b")
d = A("d")
f = B("f")
c = B("c")
a = A("a")
n = A("n")

m.x = d
h.v = n
h.u = n
b.v = d
b.u = m
d.x = m
f.v = a
f.u = d
c.v = n
c.u = m
a.x = n
n.x = m
assert m.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

m = A("m")
h = B("h")
b = B("b")
d = A("d")
f = B("f")
c = B("c")
a = A("a")
n = A("n")

m.x = d
h.v = n
h.u = n
b.v = d
b.u = m
d.x = m
f.v = a
f.u = d
c.v = n
c.u = m
a.x = n
n.x = m
assert m.x.x.x.x.txt == "m"