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

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

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

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

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

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

j.p = g
j.x = g
g.p = j
g.z = b
b.p = j
b.z = g
assert j.p.z.z.txt == "g"