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

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

m = A("m")
j = B("j")
k = A("k")
a = B("a")

m.x = a
m.p = j
j.t = m
j.u = a
k.x = j
k.p = j
a.t = k
a.u = j
assert m.p.t.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: B = None
        self.txt = txt

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

m = A("m")
j = B("j")
k = A("k")
a = B("a")

m.x = a
m.p = j
j.t = m
j.u = a
k.x = j
k.p = j
a.t = k
a.u = j
assert m.p.t.x.t.txt == "k"