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.q: A = None
        self.txt = txt

d = A("d")
b = B("b")
g = B("g")
h = A("h")
m = B("m")
e = B("e")
j = A("j")
n = B("n")
i = A("i")
k = A("k")

d.v = h
b.u = k
b.q = j
g.u = k
g.q = d
h.v = k
m.u = k
m.q = j
e.u = h
e.q = k
j.v = h
n.u = h
n.q = d
i.v = j
k.v = d
assert j.v.v.v.v.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.q: A = None
        self.txt = txt

d = A("d")
b = B("b")
g = B("g")
h = A("h")
m = B("m")
e = B("e")
j = A("j")
n = B("n")
i = A("i")
k = A("k")

d.v = h
b.u = k
b.q = j
g.u = k
g.q = d
h.v = k
m.u = k
m.q = j
e.u = h
e.q = k
j.v = h
n.u = h
n.q = d
i.v = j
k.v = d
assert j.v.v.v.v.v.v.txt == "d"