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

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

f = A("f")
b = B("b")
e = A("e")
d = B("d")
k = A("k")

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

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

f = A("f")
b = B("b")
e = A("e")
d = B("d")
k = A("k")

f.t = k
f.q = e
b.p = k
e.t = f
e.q = f
d.p = k
k.t = e
k.q = e
assert k.t.q.q.txt == "e"