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

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

g = A("g")
j = B("j")
i = A("i")

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

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

g = A("g")
j = B("j")
i = A("i")

g.p = i
g.x = j
j.v = i
i.p = g
i.x = j
assert i.x.v.x.txt == "j"