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

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

b = A("b")
i = B("i")
n = B("n")
g = A("g")

b.v = i
b.u = g
i.v = n
n.v = i
g.v = n
g.u = b
assert g.u.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.u: A = None
        self.txt = txt

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

b = A("b")
i = B("i")
n = B("n")
g = A("g")

b.v = i
b.u = g
i.v = n
n.v = i
g.v = n
g.u = b
assert g.u.u.v.txt == "n"