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

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

b = A("b")
g = B("g")
e = A("e")
k = B("k")
j = A("j")
h = B("h")
d = B("d")
f = B("f")
i = B("i")
a = A("a")

b.x = d
b.v = j
g.u = e
e.x = d
e.v = b
k.u = b
j.x = i
j.v = b
h.u = b
d.u = j
f.u = a
i.u = j
a.x = k
a.v = b
assert g.u.x.u.x.u.x.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.v: A = None
        self.txt = txt

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

b = A("b")
g = B("g")
e = A("e")
k = B("k")
j = A("j")
h = B("h")
d = B("d")
f = B("f")
i = B("i")
a = A("a")

b.x = d
b.v = j
g.u = e
e.x = d
e.v = b
k.u = b
j.x = i
j.v = b
h.u = b
d.u = j
f.u = a
i.u = j
a.x = k
a.v = b
assert g.u.x.u.x.u.x.u.x.txt == "i"