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

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

f = A("f")
m = B("m")
b = B("b")
e = B("e")
j = A("j")
g = A("g")
h = B("h")
c = A("c")
i = B("i")
n = A("n")

f.v = c
m.w = f
m.t = i
b.w = c
b.t = e
e.w = n
e.t = b
j.v = g
g.v = f
h.w = j
h.t = b
c.v = f
i.w = g
i.t = m
n.v = j
assert m.t.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

f = A("f")
m = B("m")
b = B("b")
e = B("e")
j = A("j")
g = A("g")
h = B("h")
c = A("c")
i = B("i")
n = A("n")

f.v = c
m.w = f
m.t = i
b.w = c
b.t = e
e.w = n
e.t = b
j.v = g
g.v = f
h.w = j
h.t = b
c.v = f
i.w = g
i.t = m
n.v = j
assert m.t.t.w.txt == "f"