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

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

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

j.p = d
g.p = d
d.p = j
l.p = d
assert j.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

j.p = d
g.p = d
d.p = j
l.p = d
assert j.p.p.p.txt == "d"