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

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

c = A("c")
m = B("m")
a = A("a")
e = B("e")
i = A("i")
g = B("g")
b = A("b")
d = A("d")

c.v = d
m.z = g
m.u = c
a.v = c
e.z = m
e.u = c
i.v = a
g.z = e
g.u = i
b.v = c
d.v = b
assert g.u.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.z: B = None
        self.u: A = None
        self.txt = txt

c = A("c")
m = B("m")
a = A("a")
e = B("e")
i = A("i")
g = B("g")
b = A("b")
d = A("d")

c.v = d
m.z = g
m.u = c
a.v = c
e.z = m
e.u = c
i.v = a
g.z = e
g.u = i
b.v = c
d.v = b
assert g.u.v.v.txt == "c"