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

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

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

a.t = k
m.y = a
m.r = a
k.y = a
k.r = a
f.y = a
f.r = a
assert a.t.r.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

a.t = k
m.y = a
m.r = a
k.y = a
k.r = a
f.y = a
f.r = a
assert a.t.r.t.y.txt == "a"