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

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

b = A("b")
g = B("g")
c = A("c")
l = A("l")

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

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

b = A("b")
g = B("g")
c = A("c")
l = A("l")

b.v = g
g.u = b
c.v = g
l.v = g
assert g.u.v.u.txt == "b"