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

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

g = A("g")
k = B("k")
b = A("b")

g.t = k
k.p = b
b.t = k
assert g.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

g = A("g")
k = B("k")
b = A("b")

g.t = k
k.p = b
b.t = k
assert g.t.p.t.txt == "k"