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

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

j = A("j")
f = B("f")
g = A("g")
b = A("b")

j.y = f
j.x = b
f.v = j
g.y = f
g.x = j
b.y = f
b.x = g
assert j.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: A = None
        self.txt = txt

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

j = A("j")
f = B("f")
g = A("g")
b = A("b")

j.y = f
j.x = b
f.v = j
g.y = f
g.x = j
b.y = f
b.x = g
assert j.x.x.x.x.txt == "b"