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

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

a = A("a")
g = B("g")
d = B("d")
e = B("e")
n = B("n")
c = B("c")

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

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

a = A("a")
g = B("g")
d = B("d")
e = B("e")
n = B("n")
c = B("c")

a.s = c
a.u = e
g.p = n
g.y = a
d.p = n
d.y = a
e.p = d
e.y = a
n.p = g
n.y = a
c.p = d
c.y = a
assert a.s.y.s.txt == "c"