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

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

g = A("g")
n = B("n")
k = A("k")
c = A("c")
f = A("f")
d = A("d")
b = A("b")
e = B("e")
m = A("m")
j = B("j")

g.x = n
n.u = e
n.x = c
k.x = j
c.x = e
f.x = e
d.x = j
b.x = j
e.u = j
e.x = k
m.x = e
j.u = n
j.x = k
assert k.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

g = A("g")
n = B("n")
k = A("k")
c = A("c")
f = A("f")
d = A("d")
b = A("b")
e = B("e")
m = A("m")
j = B("j")

g.x = n
n.u = e
n.x = c
k.x = j
c.x = e
f.x = e
d.x = j
b.x = j
e.u = j
e.x = k
m.x = e
j.u = n
j.x = k
assert k.x.x.x.x.x.x.x.txt == "j"