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

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

g = A("g")
e = B("e")
k = A("k")
h = A("h")

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

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

g = A("g")
e = B("e")
k = A("k")
h = A("h")

g.r = h
g.t = e
e.p = g
k.r = g
k.t = e
h.r = k
h.t = e
assert k.r.r.r.txt == "k"