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

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

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

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

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

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

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