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

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

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

d.t = j
g.v = d
b.t = j
n.t = b
a.v = b
m.v = f
f.t = h
h.t = d
j.t = n
c.v = d
assert d.t.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.v: A = None
        self.txt = txt

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

d.t = j
g.v = d
b.t = j
n.t = b
a.v = b
m.v = f
f.t = h
h.t = d
j.t = n
c.v = d
assert d.t.t.t.t.txt == "j"