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

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

g = A("g")
a = B("a")
h = A("h")
c = A("c")
n = B("n")
d = B("d")
i = A("i")

g.v = h
g.w = i
a.u = d
h.v = c
h.w = i
c.v = i
c.w = i
n.u = a
d.u = n
i.v = h
i.w = c
assert a.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: A = None
        self.txt = txt

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

g = A("g")
a = B("a")
h = A("h")
c = A("c")
n = B("n")
d = B("d")
i = A("i")

g.v = h
g.w = i
a.u = d
h.v = c
h.w = i
c.v = i
c.w = i
n.u = a
d.u = n
i.v = h
i.w = c
assert a.u.u.u.u.u.txt == "n"