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

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

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

b.p = a
b.y = g
c.s = b
a.s = b
g.s = b
assert c.s.y.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: B = None
        self.txt = txt

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

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

b.p = a
b.y = g
c.s = b
a.s = b
g.s = b
assert c.s.y.s.y.txt == "g"