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

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

g = A("g")
k = B("k")
i = A("i")
b = A("b")
c = A("c")
j = A("j")
n = A("n")
h = B("h")

g.x = j
k.s = h
k.w = i
i.x = j
b.x = g
c.x = n
j.x = i
n.x = j
h.s = k
h.w = j
assert n.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

g = A("g")
k = B("k")
i = A("i")
b = A("b")
c = A("c")
j = A("j")
n = A("n")
h = B("h")

g.x = j
k.s = h
k.w = i
i.x = j
b.x = g
c.x = n
j.x = i
n.x = j
h.s = k
h.w = j
assert n.x.x.x.txt == "j"