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

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

g = A("g")
j = B("j")
n = A("n")
f = A("f")
m = A("m")

g.s = j
j.p = m
n.s = j
f.s = j
m.s = j
assert m.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

g = A("g")
j = B("j")
n = A("n")
f = A("f")
m = A("m")

g.s = j
j.p = m
n.s = j
f.s = j
m.s = j
assert m.s.p.s.txt == "j"