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

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

g = A("g")
a = B("a")
d = B("d")
j = A("j")

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

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

g = A("g")
a = B("a")
d = B("d")
j = A("j")

g.s = a
g.y = j
a.u = d
d.u = a
j.s = a
j.y = g
assert d.u.u.u.txt == "a"