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

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

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

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

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

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