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

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

l = A("l")
f = B("f")
h = A("h")
d = A("d")

l.t = f
l.p = h
f.q = l
h.t = f
h.p = l
d.t = f
d.p = l
assert f.q.p.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: A = None
        self.txt = txt

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

l = A("l")
f = B("f")
h = A("h")
d = A("d")

l.t = f
l.p = h
f.q = l
h.t = f
h.p = l
d.t = f
d.p = l
assert f.q.p.p.t.txt == "f"