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

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

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

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

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

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

b.s = g
b.y = e
d.p = e
e.p = d
g.s = b
g.y = d
j.s = b
j.y = e
assert g.s.s.s.y.p.txt == "d"